:root {
  --primary: #2f6fed;
  --primary-dark: #1f4fc4;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1c2333;
  --text-muted: #6b7280;
  --border: #e3e7ef;
  --danger: #e0483e;
  --warn: #d98c1f;
  --ok: #2fa85a;
  --radius: 14px;
  --nav-height: 64px;
  --topbar-height: 42px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0 0 8px; }

input, select, textarea, button {
  font-family: inherit;
  font-size: 16px;
}

/* ---------------- Login ---------------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--primary) 0%, #6f8ef7 100%);
}
.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 40px rgba(20, 30, 60, 0.25);
}
.login-card h1 { font-size: 22px; text-align: center; line-height: 1.4; }
.en-subtitle { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.subtitle { text-align: center; color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--text-muted); }
.login-card input { width: 100%; margin-top: 6px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }

/* ---------------- App shell ---------------- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--nav-height);
}
.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-weight: 700; font-size: 14px; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.topbar-user .btn-link { padding: 4px 6px; font-size: 12px; }

.content {
  flex: 1;
  padding: 10px 16px 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.15s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.view-header h2 { font-size: 17px; }
.view-header input[type="month"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(20, 30, 60, 0.06);
}

.form-card label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.form-card input, .form-card select, .form-card textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.form-card textarea { resize: vertical; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #eef2fd; color: var(--primary-dark); }
.btn-link { background: none; color: var(--primary); padding: 8px; }
.btn-danger { background: #fdeceb; color: var(--danger); }

.error-text { color: var(--danger); font-size: 13px; margin-bottom: 10px; }
.success-text { color: var(--ok); font-size: 13px; margin-bottom: 10px; }

/* Summary / progress */
.summary-card { }
.summary-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.summary-row strong { font-size: 22px; }
.summary-row.small { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.progress-track { height: 10px; border-radius: 6px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; background: var(--ok); width: 0%; transition: width 0.3s; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }
.badge-note { margin-top: 10px; font-size: 12px; background: #fff4e0; color: var(--warn); padding: 6px 10px; border-radius: 8px; display: inline-block; }

/* Record list */
.record-list { list-style: none; margin: 0; padding: 0; }
.record-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.record-item:last-child { border-bottom: none; }
.record-main { flex: 1; min-width: 0; }
.record-title { font-weight: 600; font-size: 14px; }
.record-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; word-break: break-word; }
.record-hours { font-weight: 700; color: var(--primary); white-space: nowrap; }
.record-actions button {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
}
.empty-hint { color: var(--text-muted); font-size: 13px; text-align: center; padding: 12px 0; }

/* status badges */
.status-badge { padding: 3px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-ok { background: #e6f7ec; color: var(--ok); }
.status-danger { background: #fdeceb; color: var(--danger); }

/* Period navigator */
.period-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
}
.period-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  color: var(--primary);
  cursor: pointer;
}
.period-label {
  font-weight: 700;
  font-size: 15px;
  min-width: 190px;
  text-align: center;
}
.period-today-btn {
  display: block;
  margin: 0 auto 16px;
  font-size: 12px;
}
.hint-text {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.6;
}

/* Admin cap form */
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.inline-form input[type="number"] { width: 110px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.inline-form input[type="text"] { flex: 1; min-width: 160px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }

/* Table */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
.data-table th, .data-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { color: var(--text-muted); font-weight: 600; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 6px 2px;
}
.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--primary); font-weight: 700; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c2333;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

/* ---------------- Desktop / tablet ---------------- */
@media (min-width: 860px) {
  .app-shell { padding-bottom: 0; padding-left: 220px; }
  .bottom-nav {
    top: 0;
    left: 0;
    right: auto;
    bottom: 0;
    width: 220px;
    height: 100vh;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    padding-top: 16px;
  }
  .nav-btn { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 12px 20px; font-size: 14px; }
  .topbar { position: sticky; }
  .content { padding: 24px; }
}
