: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; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .search-wrap { flex: 0 0 auto; }

.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); }
}
.burger {
  display: none;
  align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 auto;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface); color: var(--text);
  font-size: 16px; cursor: pointer; padding: 0;
}
.sidebar-close { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 720px) {
  .burger { display: inline-flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 100;
    width: 260px; flex: 0 0 260px;
    transform: translateX(-100%);
    transition: transform .18s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close {
    display: flex; align-items: center; justify-content: center;
    position: absolute; top: 14px; right: 12px;
    width: 28px; height: 28px; border-radius: 7px; border: none;
    background: rgba(255,255,255,.08); color: #cdd6e3; font-size: 15px; cursor: pointer;
  }

  .sidebar-backdrop {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(16, 24, 40, .45);
  }
  .sidebar-backdrop.open { display: block; }

  .grid.cols-2, .grid.cols-4, .grid.cols-5 { grid-template-columns: minmax(0, 1fr); }
  .content { padding: 16px 12px 50px; }

  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar .search-wrap { display: none; }
}

/* 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); }
}

/* drag-and-drop file dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; text-align: center; cursor: pointer; padding: 22px 16px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); transition: border-color .12s, background .12s;
}
.dropzone:hover { border-color: var(--muted-2); }
.dropzone.drag { border-color: var(--brand); background: rgba(31, 94, 255, .06); }
.dropzone-icon { font-size: 20px; color: var(--muted-2); }
.dropzone-text { font-size: 13px; color: var(--muted); }
.dropzone-row {
  display: flex; align-items: center; gap: 10px; margin: 10px 0 0; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.dropzone-row label {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; color: var(--text); margin: 0;
}
.dropzone-row input { width: 190px; flex: 0 0 auto; }

.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; }

/* time inputs share the same look as the other form controls */
input[type=time] {
  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[type=time]:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 94, 255, .12);
}

/* calendar colour picker: a row of clickable swatches, one radio each */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch { position: relative; }
.color-swatch input { position: absolute; opacity: 0; width: 28px; height: 28px; margin: 0; cursor: pointer; }
.color-swatch span {
  display: block; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.color-swatch input:checked + span { border-color: var(--text); box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--text); }
.color-swatch.color-auto span {
  background: repeating-conic-gradient(#d8dee6 0% 25%, #eef1f5 0% 50%) 0 0/12px 12px;
}

/* team member checkboxes on the job form */
.team-picker { display: flex; flex-direction: column; gap: 7px; max-height: 220px; overflow-y: auto; }

/* month calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow {
  padding: 8px 10px; font-size: 11.5px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.cal-cell {
  min-height: 112px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.cal-grid .cal-cell:nth-child(7n) { border-right: none; }
.cal-cell-out { background: var(--surface-2); }
.cal-cell-out .cal-daynum { color: var(--muted-2); }
.cal-cell-today { background: var(--brand-soft); }
.cal-cell-head { display: flex; align-items: center; justify-content: space-between; }
.cal-daynum { font-size: 12.5px; font-weight: 650; }
.cal-add {
  font-size: 13px; font-weight: 700; color: var(--muted); width: 18px; height: 18px; line-height: 18px;
  text-align: center; border-radius: 5px;
}
.cal-add:hover { background: var(--border); text-decoration: none; }
.cal-event {
  display: flex; flex-direction: column; gap: 1px; padding: 3px 6px; border-radius: 5px;
  border-left: 3px solid; font-size: 11.5px; line-height: 1.3; text-decoration: none;
}
.cal-event:hover { filter: brightness(.96); text-decoration: none; }
.cal-event-time { font-weight: 650; font-size: 10.5px; opacity: .85; }
.cal-event-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-event-team { font-size: 10px; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) {
  .cal-grid { grid-template-columns: repeat(7, minmax(76px, 1fr)); overflow-x: auto; }
}

/* header/login logo */
.qmi-logo { display: block; margin: 0 auto 10px; }
.sidebar-logo { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; }
.sidebar-logo img { height: 34px; width: auto; }
.filters .checkline { white-space: nowrap; padding-bottom: 7px; }
