:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e3e8ef;
  --border-strong: #cdd5df;
  --text: #1c2433;
  --text-soft: #5b6676;
  --text-faint: #8a94a3;
  --primary: #2f56d9;
  --primary-hover: #2647b8;
  --primary-soft: #e8edfc;
  --green: #00c878;
  --green-soft: #d9f6ea;
  --red: #d9463e;
  --red-soft: #fdeceb;
  --weekend: #e6e9f0;
  --weekend-head: #d5dae4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand { display: flex; align-items: center; text-decoration: none; }

.logo {
  font-weight: 900; font-size: 21px; letter-spacing: -.04em; line-height: 1;
  color: #0b0b0d; white-space: nowrap;
}
.logo .logo-accent { color: #00e087; }
.logo.logo-lg { font-size: 28px; }

.topbar-nav { display: flex; gap: 4px; margin-left: 12px; }

.topbar-nav a {
  color: var(--text-soft); text-decoration: none; font-weight: 500;
  padding: 7px 12px; border-radius: 8px;
}
.topbar-nav a:hover { background: var(--bg); color: var(--text); }
.topbar-nav a.active { background: var(--primary-soft); color: var(--primary); }

.topbar-spacer { flex: 1; }

.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user-chip .who { line-height: 1.2; }
.user-chip .who .name { font-weight: 600; font-size: 13px; }
.user-chip .who .role { font-size: 11.5px; color: var(--text-faint); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 13.5px;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--bg); color: var(--text); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.danger:hover { background: #fbdcda; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Layout ---------- */

.page { max-width: 1060px; margin: 0 auto; padding: 32px 24px 64px; }
.page.wide { max-width: none; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; letter-spacing: -.02em; }
.page-head .sub { color: var(--text-soft); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card .card-body { padding: 22px; }
.card h2 { font-size: 15px; margin-bottom: 16px; }

/* ---------- Dashboard ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat { padding: 18px 20px; }
.stat .label { color: var(--text-soft); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 30px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat .value .accent { color: var(--primary); }

.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 32px; }
.quick {
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
  padding: 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: var(--text);
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.quick:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.quick .icon {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  font-size: 18px; background: var(--primary-soft);
}
.quick .t { font-weight: 650; }
.quick .d { color: var(--text-soft); font-size: 12.5px; line-height: 1.45; }

/* ---------- Tables (admin lists) ---------- */

table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); padding: 10px 16px; border-bottom: 1px solid var(--border);
}
table.list td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: #fafbfd; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.admin { background: var(--primary-soft); color: var(--primary); }
.pill.client { background: var(--green-soft); color: #068a58; }
.pill.live { background: var(--green-soft); color: #068a58; }
.pill.upcoming { background: #fff4d6; color: #96690a; }
.pill.finished { background: var(--bg); color: var(--text-faint); }

/* ---------- Forms ---------- */

.form-grid { display: grid; gap: 16px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr; } }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field .hint { font-weight: 400; color: var(--text-faint); font-size: 12px; margin-left: 6px; }
.field input, .field select {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* checkbox field (Show Costs) */
.check-field {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface);
}
.check-field:hover { background: var(--bg); }
.check-field input[type="checkbox"] { width: 17px; height: 17px; margin-top: 1px; accent-color: var(--primary); cursor: pointer; flex: none; }
.check-field > span { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.check-field .hint { color: var(--text-faint); font-size: 12.5px; margin-left: 0; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; z-index: 400; background: rgba(16, 24, 40, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 680px; max-width: 100%; animation: modal-in .14s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; }
.modal-close {
  border: none; background: none; font-size: 16px; color: var(--text-faint);
  border-radius: 7px; width: 30px; height: 30px; line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 22px; }
.modal-body input:disabled { background: var(--bg); color: var(--text-soft); cursor: not-allowed; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: none; font-size: 15px; padding: 5px 7px; border-radius: 6px;
  color: var(--text-faint); line-height: 1;
}
.pw-toggle:hover { background: var(--bg); color: var(--text); }

/* inline edit (actions list) */
.inline-edit { display: flex; gap: 8px; align-items: center; }
.inline-edit input {
  flex: 1; padding: 6px 10px; border-radius: 7px; border: 1px solid var(--border-strong); outline: none;
}
.inline-edit input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-error { color: var(--red); background: var(--red-soft); border-radius: 8px; padding: 10px 14px; font-weight: 500; }

/* ---------- Login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, #eef1f8 0%, #f4f6fa 45%, #e9edf7 100%); }
.login-card { width: 400px; max-width: 100%; }
.login-card .card-body { padding: 34px; }
.login-brand { display: flex; align-items: center; margin-bottom: 8px; }
.login-sub { color: var(--text-soft); margin-bottom: 24px; }

/* ---------- Event view: toolbar ---------- */

.event-toolbar {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 20px;
}
.event-toolbar .field { min-width: 220px; }
.event-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.meta-chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font-size: 12.5px; color: var(--text-soft); box-shadow: var(--shadow);
}
.meta-chip b { color: var(--text); font-weight: 650; }

.legend { display: flex; gap: 16px; align-items: center; margin: 14px 2px 0; color: var(--text-soft); font-size: 12.5px; flex-wrap: wrap; }
.legend .swatch { display: inline-block; width: 13px; height: 13px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0,0,0,.08); }

/* ---------- Schedule table ---------- */

.sched-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.sched-scroll { overflow-x: auto; overflow-y: visible; max-width: 100%; }

table.sched { border-collapse: separate; border-spacing: 0; font-size: 12.5px; width: max-content; min-width: 100%; }

table.sched th, table.sched td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

/* header rows — plain rows (not vertically sticky) so they always sit above the task rows */
table.sched thead th { font-weight: 600; }
table.sched thead tr.h-month th { height: 30px; background: #f0f3f9; color: var(--text-soft); font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; }
table.sched thead tr.h-dow th { height: 26px; font-size: 11px; color: var(--text-faint); font-weight: 600; }
table.sched thead tr.h-day th { height: 26px; font-size: 12px; }

/* uniform body row height keeps day cells aligned with the task labels */
table.sched tbody td { height: 32px; vertical-align: middle; }
table.sched thead th.wkend { background: var(--weekend-head); }
table.sched thead tr.h-month th.wkend { background: var(--weekend-head); }

/* corner + sticky first column */
table.sched .col-action {
  position: sticky; left: 0; z-index: 4;
  min-width: 268px; max-width: 268px; width: 268px;
  text-align: left; padding: 0 12px;
  border-right: 2px solid var(--border-strong);
}
table.sched thead .col-action { z-index: 6; background: #f0f3f9; font-size: 12.5px; letter-spacing: 0; text-transform: none; color: var(--text); font-weight: 700; }

/* cost column (sticky right) */
table.sched .col-cost {
  position: sticky; right: 0; z-index: 4;
  min-width: 112px; max-width: 112px; width: 112px;
  border-left: 2px solid var(--border-strong);
  text-align: right;
}
table.sched thead .col-cost { z-index: 6; background: #f0f3f9; font-weight: 700; color: var(--text); }

/* day cells */
table.sched .day { width: 36px; min-width: 36px; max-width: 36px; text-align: center; padding: 0; height: 32px; position: relative; }
table.sched td.day { cursor: cell; font-weight: 600; user-select: none; }
table.sched td.day.readonly { cursor: default; }
table.sched td.day.wkend { background: var(--weekend); }
table.sched td.day.green { background: var(--green) !important; color: #fff; }
table.sched td.day:not(.readonly):hover { outline: 2px solid var(--primary); outline-offset: -2px; }

table.sched td.day .cell-text { display: inline-block; overflow: hidden; white-space: nowrap; max-width: 34px; }

table.sched td.day input.cell-edit {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 2px solid var(--primary); outline: none; text-align: center;
  font: inherit; font-weight: 600; background: #fff; color: var(--text); z-index: 5;
}

/* row label cells */
td.col-action { font-weight: 600; }
td.col-action .row-label-inner { display: flex; align-items: center; gap: 8px; height: 32px; }
td.col-action .drag-handle { color: var(--text-faint); cursor: grab; font-size: 13px; letter-spacing: -1px; padding: 0 2px; flex: none; }
td.col-action .lock { color: var(--text-faint); font-size: 11px; flex: none; }
td.col-action .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
td.col-action .row-del {
  flex: none; border: none; background: none; color: var(--text-faint); font-size: 14px;
  border-radius: 5px; width: 20px; height: 20px; line-height: 1; visibility: hidden;
}
tr:hover td.col-action .row-del { visibility: visible; }
td.col-action .row-del:hover { background: var(--red-soft); color: var(--red); }


tr.dragging td { opacity: .45; }
tr.drop-above td { box-shadow: inset 0 3px 0 var(--primary); }
tr.drop-below td { box-shadow: inset 0 -3px 0 var(--primary); }

/* cost cells — derived from the breakdown tables, read-only */
td.col-cost.cost-static { padding: 0 10px; font-weight: 600; color: var(--text-soft); }
tr.row-movable td.col-cost.cost-static { color: var(--text); }

/* add-row */
tr.add-row td.col-action { padding: 0; }
.add-row-btn {
  width: 100%; height: 36px; border: none; background: none; color: var(--primary);
  font-weight: 650; text-align: left; padding: 0 12px; font-size: 13px;
}
.add-row-btn:hover { background: var(--primary-soft); }
tr.add-row td { background: #fbfcfe; }

/* total row */
tr.total-row td { border-top: 2px solid var(--border-strong); font-weight: 750; background: #f7f9fc; }
tr.total-row td.col-action { text-transform: uppercase; font-size: 11.5px; letter-spacing: .08em; color: var(--text-soft); }
tr.total-row td.col-cost { padding: 0 10px; height: 36px; vertical-align: middle; font-size: 13px; }

/* ---------- Cost breakdown tables ---------- */

.bd-section { margin-top: 36px; }
.bd-heading { font-size: 17px; letter-spacing: -.01em; }
.bd-sub { color: var(--text-soft); margin: 4px 0 18px; font-size: 13px; }

table.sched.bd { min-width: 0; }
table.sched.bd thead th.bd-group {
  height: 30px; background: #f0f3f9; color: var(--text-soft);
  font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase;
}
table.sched.bd thead th.bd-col {
  min-width: 112px; width: 112px; text-align: right; padding: 0 10px; height: 32px;
  background: #f0f3f9; font-size: 12px; white-space: nowrap;
}
table.sched.bd td.bd-cell { padding: 0; min-width: 112px; width: 112px; text-align: right; }
table.sched.bd .col-action { min-width: 200px; max-width: 200px; width: 200px; }

/* stronger divider at the start of each column group */
table.sched.bd .grp-start { border-left: 2px solid var(--border-strong); }

.bd-input {
  width: 100%; height: 32px; border: none; outline: none; text-align: right;
  padding: 0 10px; font: inherit; font-weight: 600; background: transparent;
}
.bd-input:focus { box-shadow: inset 0 0 0 2px var(--primary); }
.bd-input::placeholder { color: var(--text-faint); font-weight: 400; }
.bd-static { display: inline-block; padding: 0 10px; font-weight: 600; }

td.bd-total { text-align: right; padding: 0 10px; font-size: 13px; }
.bd-renamable { cursor: text; border-radius: 5px; }
.bd-renamable:hover { background: var(--primary-soft); box-shadow: 0 0 0 4px var(--primary-soft); }

/* ---------- Action menu popover ---------- */

.popover {
  position: fixed; z-index: 100; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 240px; max-height: 320px;
  overflow-y: auto; padding: 6px;
}
.popover .pop-title { padding: 8px 10px 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); }
.popover button.pop-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; background: none;
  border-radius: 7px; font-weight: 500;
}
.popover button.pop-item:hover { background: var(--primary-soft); color: var(--primary); }
.popover .pop-empty { padding: 10px; color: var(--text-faint); }

/* ---------- Tooltip ---------- */

.cell-tooltip {
  position: fixed; z-index: 200; background: #1c2433; color: #fff; padding: 7px 11px;
  border-radius: 8px; font-size: 12.5px; font-weight: 500; max-width: 280px;
  box-shadow: var(--shadow-lg); pointer-events: none; white-space: pre-wrap; word-break: break-word;
}
.cell-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: #1c2433;
}

/* ---------- Toasts ---------- */

#toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1c2433; color: #fff; padding: 11px 16px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in .18s ease-out;
}
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty-state { text-align: center; padding: 56px 20px; color: var(--text-soft); }
.empty-state .big { font-size: 40px; margin-bottom: 12px; }
.muted { color: var(--text-faint); }
.mt { margin-top: 20px; }
