:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #e0e7ff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 20% 10%, #dbeafe, transparent 50%), radial-gradient(circle at 90% 90%, #e0e7ff, transparent 45%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand img { height: 40px; width: auto; }
.brand-sep { width: 1px; align-self: stretch; background: var(--border); }
.brand-login { flex-direction: column; text-align: center; gap: 6px; }
.brand-login img { height: 56px; margin-bottom: 6px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-card h2 { margin: 0 0 4px; font-size: 18px; }
.auth-card .sub { margin: 0 0 20px; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }
.auth-foot { margin-top: 20px; text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field label .req { color: var(--danger); }
.field .hint { color: var(--muted); font-size: 12px; }
input, select, textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; background: var(--surface); width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 90px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-2 .full { grid-column: 1 / -1; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13px; }
.form-error:empty { display: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; background: var(--surface); border-color: var(--border); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; padding: 10px 14px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 4px 8px; font-size: 13px; border-color: transparent; background: transparent; color: var(--muted); }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Layout ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.topbar .brand { margin: 0; gap: 10px; }
.topbar .brand img { height: 30px; width: auto; }
.topbar .brand h1 { font-size: 18px; }
.topbar .brand p { font-size: 12px; }
.topbar .spacer { flex: 1; }
.user-chip { text-align: right; line-height: 1.3; }
.user-chip strong { display: block; }
.user-chip span { color: var(--muted); font-size: 12px; }
.tabs { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-pad { padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .value small { font-size: 14px; color: var(--muted); font-weight: 600; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 60px; gap: 10px; align-items: center; margin-bottom: 8px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td .desc { white-space: pre-wrap; max-width: 480px; }
.muted { color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-amber { background: var(--warn-soft); color: var(--warn); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { margin: 0; min-width: 150px; }
.toolbar input[type=search] { min-width: 240px; }

/* ---------- Week view ---------- */
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-nav .range { font-weight: 700; min-width: 210px; text-align: center; }
.week-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.week-summary .stat { flex: 1; min-width: 160px; }
.days { display: flex; flex-direction: column; gap: 10px; }
.day { padding: 0; overflow: hidden; }
.day-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.day-head .date { font-weight: 700; }
.day-head .dow { color: var(--muted); font-size: 12px; }
.day-head .spacer { flex: 1; }
.day-head .total { font-weight: 700; font-variant-numeric: tabular-nums; }
.day.today { border-color: var(--primary); }
.day.today .day-head { background: var(--primary-soft); }
.day.future { opacity: .55; }
.day.weekend .day-head { background: #f1f5f9; }
.entry { display: grid; grid-template-columns: 70px 1fr auto; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); align-items: start; }
.entry:last-child { border-bottom: 0; }
.entry .hrs { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--primary); }
.entry .proj { font-size: 12px; color: var(--muted); font-weight: 600; }
.entry .desc { white-space: pre-wrap; word-break: break-word; }
.day-empty { padding: 10px 14px; color: var(--muted); font-size: 13px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(15,23,42,.25); }
.modal.wide { max-width: 720px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px 4px; }
.modal-foot { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 6px 0 10px; grid-column: 1 / -1; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; animation: pop .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }


/* ---------- Assigned tasks ---------- */
.tasks { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-bottom: 20px; }
.task { padding: 14px; display: flex; flex-direction: column; gap: 6px; border-left: 4px solid var(--primary); }
.task.done { border-left-color: var(--success); opacity: .75; }
.task-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.task-meta { color: var(--muted); font-size: 12px; font-weight: 600; }
.task-desc { white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.task-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.task-foot .spacer { flex: 1; }
.task-hrs { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.task-status { width: auto; padding: 5px 8px; font-size: 13px; }
input.readonly, input[readonly] { background: var(--surface-2); color: var(--muted); }


/* ---------- Avatars & photo ---------- */
.avatar { border-radius: 50%; object-fit: cover; display: inline-block; vertical-align: middle; background: var(--primary-soft); }
.avatar-ph { display: inline-grid; place-items: center; color: var(--primary); font-weight: 700; }
.photo-field { flex-direction: row; align-items: center; gap: 16px; }
.photo-field label.btn { cursor: pointer; }

/* ---------- ID card (view only) ---------- */
.idcard-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .75); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 60; overflow-y: auto; }
.idcard-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.idcard-canvas { display: block; max-width: calc(100vw - 32px); height: auto; border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.4); }
.idcard-note { margin: 0; color: #e2e8f0; font-size: 12px; }

@media (max-width: 760px) {
  .two-col, .grid-2 { grid-template-columns: 1fr; }
  .user-chip { display: none; }
  .topbar .brand p { display: none; }
  .entry { grid-template-columns: 56px 1fr; }
  .entry .entry-actions { grid-column: 1 / -1; justify-self: end; }
  .bar-row { grid-template-columns: 100px 1fr 50px; }
  .toolbar input[type=search] { min-width: 0; }
}
