:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --border: #e3e7ec;
  --border-strong: #cbd3dc;
  --text: #16202b;
  --muted: #667487;
  --muted-2: #8b98a9;
  --brand: #1f5eff;
  --brand-dark: #1748c9;
  --brand-soft: #eef3ff;
  --green: #0f9d63;
  --green-soft: #e8f7f0;
  --red: #dc2626;
  --red-soft: #fdeceb;
  --amber: #d97706;
  --amber-soft: #fdf3e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

/* ---------------------------------------------------------------- layout */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: #101826;
  color: #cdd6e3;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  padding: 18px 18px 14px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand span { color: #6f9dff; }
.sidebar .brand small {
  display: block; font-size: 11px; font-weight: 500; color: #7c8aa0;
  letter-spacing: 0; margin-top: 2px;
}

.sidebar nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar .nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #64748b; padding: 12px 10px 5px; font-weight: 600;
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 7px; color: #cdd6e3;
  font-size: 13.5px; font-weight: 500; margin-bottom: 1px;
}
.sidebar a.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.sidebar a.nav-item.active { background: var(--brand); color: #fff; }
.sidebar a.nav-item .ico { width: 16px; text-align: center; opacity: .9; font-size: 13px; }
.sidebar a.nav-item .count {
  margin-left: auto; background: rgba(255,255,255,.12); border-radius: 20px;
  padding: 1px 7px; font-size: 11px;
}

.sidebar .foot {
  border-top: 1px solid rgba(255,255,255,.08); padding: 12px;
  font-size: 12px; color: #8b98a9;
}
.sidebar .foot a { color: #cdd6e3; }
.sidebar .foot .who { color: #fff; font-weight: 600; font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 17px; }
.topbar .spacer { flex: 1; }

.content { padding: 22px 24px 60px; max-width: 1500px; width: 100%; }

/* ---------------------------------------------------------------- components */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card > .card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card > .card-head h2, .card > .card-head h3 { margin: 0; }
.card > .card-head .spacer { flex: 1; }
.card > .card-body { padding: 16px; }
.card > .card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }

@media (max-width: 1100px) {
  .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .grid.cols-2, .grid.cols-4, .grid.cols-5 { grid-template-columns: minmax(0, 1fr); }
  .content { padding: 16px 12px 50px; }
}

/* stat tiles */
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 680; letter-spacing: -.02em; margin-top: 4px; }
.stat .value.sm { font-size: 19px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent-green .value { color: var(--green); }
.stat.accent-red .value { color: var(--red); }
.stat.accent-amber .value { color: var(--amber); }
.stat a { color: inherit; }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 650; padding: 9px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #f9fbfd; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .strong { font-weight: 600; }
table.data .dim { color: var(--muted); }
.table-wrap { overflow-x: auto; }

.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 26px; margin-bottom: 6px; opacity: .5; }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap; line-height: 1.4;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain { background: #eef1f5; color: #47566a; }

.pill {
  display: inline-block; padding: 1.5px 7px; border-radius: 5px; font-size: 11px;
  font-weight: 650; background: #eef1f5; color: #47566a; letter-spacing: .02em;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 550;
  cursor: pointer; text-decoration: none; line-height: 1.35; font-family: inherit;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #f3c7c4; color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 4.5px 9px; font-size: 12.5px; border-radius: 6px; }
.btn-lg { padding: 10px 18px; font-size: 15px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #eef1f5; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* forms */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600; color: #384558; margin-bottom: 5px;
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 7px; font-size: 13.5px; font-family: inherit; color: var(--text);
  background: #fff; line-height: 1.4;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 94, 255, .12);
}
textarea { min-height: 84px; resize: vertical; }
input[type=file] { font-size: 13px; padding: 7px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.checkline input { width: auto; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 720px) {
  .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
}

.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px; box-shadow: var(--shadow);
}
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters .grow input { width: 100%; }

/* flash */
.flash {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px;
  border: 1px solid; display: flex; gap: 9px; align-items: flex-start;
}
.flash-success { background: var(--green-soft); border-color: #b7e4cf; color: #0a6b45; }
.flash-error { background: var(--red-soft); border-color: #f6c9c6; color: #a5231d; }

/* detail lists */
dl.meta { margin: 0; display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 7px 12px; font-size: 13.5px; }
dl.meta dt { color: var(--muted); font-weight: 550; }
dl.meta dd { margin: 0; word-break: break-word; }

/* kanban board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.board-col {
  flex: 0 0 268px; background: #eef1f5; border-radius: var(--radius); padding: 10px;
  max-height: calc(100vh - 230px); display: flex; flex-direction: column;
}
.board-col > .col-head {
  display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: #47566a; padding: 2px 4px 9px;
}
.board-col .col-head .n {
  margin-left: auto; background: #fff; border-radius: 20px; padding: 1px 8px;
  font-size: 11px; color: var(--muted);
}
.board-col .col-body { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.job-card {
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px;
  box-shadow: var(--shadow); display: block; color: inherit;
}
.job-card:hover { text-decoration: none; box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.job-card .code { font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.job-card .t { font-weight: 600; font-size: 13.5px; margin: 3px 0 5px; }
.job-card .meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }

/* document type chips row */
.doc-types { display: flex; flex-wrap: wrap; gap: 7px; }
.doc-type-chip {
  border: 1px solid var(--border-strong); border-radius: 7px; padding: 6px 11px;
  font-size: 12.5px; font-weight: 600; color: var(--text); background: #fff;
  display: inline-flex; align-items: center; gap: 6px;
}
.doc-type-chip:hover { text-decoration: none; background: var(--brand-soft); border-color: var(--brand); }
.doc-type-chip .dot { width: 8px; height: 8px; border-radius: 50%; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 13px; font-size: 13.5px; font-weight: 550; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

.note-item { padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.note-item:last-child { border-bottom: none; }
.note-item .who { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.note-item .body { white-space: pre-wrap; }

.money-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px; border-bottom: 1px dashed var(--border); }
.money-row:last-child { border-bottom: none; }
.money-row .k { color: var(--muted); }
.money-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.money-row.total { border-top: 2px solid var(--border); border-bottom: none; margin-top: 4px; padding-top: 9px; font-size: 14.5px; }

.overdue { color: var(--red); font-weight: 600; }

.progress { height: 6px; background: #e8ecf1; border-radius: 20px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--green); }

/* login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #101826 0%, #1c2b45 100%); padding: 20px;
}
.login-card {
  background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 388px;
  box-shadow: 0 18px 44px rgba(0,0,0,.28);
}
.login-card .logo { font-size: 27px; font-weight: 750; letter-spacing: -.03em; margin-bottom: 2px; }
.login-card .logo span { color: var(--brand); }
.login-card .tag { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }

.file-preview { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fafbfc; }
.file-preview img { display: block; max-width: 100%; }
.file-preview iframe { display: block; width: 100%; height: 620px; border: 0; }

.attach-flag { color: var(--green); font-weight: 600; }
.no-attach { color: var(--muted-2); }

.inline-form { display: inline; }

@media print {
  .sidebar, .topbar, .btn, .filters { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; }
}

table.data tr.group-row td {
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  padding-top: 9px;
  padding-bottom: 9px;
}
table.data tr.group-row:hover td { background: var(--surface-2); }

/* checkboxes inside filter bars must not inherit the min-width of text inputs */
.filters input[type=checkbox] { min-width: 0; width: auto; }
.filters .checkline { white-space: nowrap; padding-bottom: 7px; }
