:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2431;
  --muted: #6b7684;
  --brand: #123a6b;
  --brand-2: #1e5fae;
  --border: #e2e6ec;
  --border-2: #eef1f5;
  --err: #b12727;
  --ok: #1a7a3f;
  --due-over: #b12727;
  --due-soon: #9a6212;
  /* Status palette (business-like, subtle) */
  --s-grey-bg:#eef2f7; --s-grey-ink:#42526b;
  --s-amber-bg:#fef4e6; --s-amber-ink:#9a6212;
  --s-blue-bg:#e8f1fb; --s-blue-ink:#1c5aa6;
  --s-green-bg:#e4f6ea; --s-green-ink:#1a7a3f;
  --s-red-bg:#fdeaea; --s-red-ink:#b12727;
  --s-mute-bg:#eceef1; --s-mute-ink:#77808c;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14.5px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---- Header ---- */
.topbar { display: flex; align-items: center; background: var(--brand); color: #fff;
  padding: 0 clamp(14px, 4vw, 22px); min-height: 56px; }
.brand { color: #fff; font-weight: 700; font-size: clamp(15px, 4vw, 18px); white-space: nowrap; }
.brand span { font-weight: 400; opacity: .85; }
.inline { display: inline; margin: 0; }

/* ---- App shell ---- */
.layout { display: flex; align-items: stretch; max-width: 1240px; margin: 0 auto; min-height: calc(100vh - 56px); }
.plain { display: block; }
.sidebar { flex: 0 0 210px; width: 210px; background: var(--card);
  border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; }
.sidenav { display: flex; flex-direction: column; gap: 3px; }
.sidenav a, .sidenav-admin { display: block; padding: 9px 12px; border-radius: 7px;
  color: var(--ink); font-weight: 600; font-size: 14px; }
.sidenav a:hover, .sidenav-admin:hover { background: #eef3f9; text-decoration: none; }
.sidenav a.active, .sidenav-admin.active { background: var(--brand-2); color: #fff; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.sidenav-admin { width: 100%; color: var(--muted); }
.who { display: flex; flex-direction: column; line-height: 1.3; }
.who-name { font-weight: 600; font-size: 13.5px; }
.who-role { color: var(--muted); font-size: 12px; }
.btn-logout { padding: 7px 12px; }
.content { flex: 1 1 auto; min-width: 0; padding: 24px clamp(14px, 4vw, 30px); }

/* ---- Page header ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- Cards ---- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.container { max-width: 960px; margin: 28px auto; padding: 0 18px; }
.auth-card { max-width: 380px; margin: 7vh auto; }

/* ---- Buttons ---- */
.btn { display: inline-block; padding: 9px 15px; border-radius: 7px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; text-align: center; line-height: 1.2; }
.btn-primary { background: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); text-decoration: none; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: #f5f7fa; text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 16px; }
.linklike { background: none; border: none; color: var(--brand-2); cursor: pointer; padding: 0; font: inherit; }

/* ---- Forms ---- */
label { display: block; margin: 13px 0 5px; font-weight: 600; font-size: 13.5px; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=url], input[type=number], input[type=date], input[type=file],
select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 14.5px; background: #fff; color: var(--ink); }
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); }
.field-error { color: var(--err); font-size: 12.5px; display: block; margin-top: 4px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-card { max-width: 760px; }

/* ---- Flash ---- */
.flashes { margin-bottom: 16px; }
.flash { padding: 10px 13px; border-radius: 7px; margin-bottom: 8px; font-size: 14px; }
.flash-error { background: var(--s-red-bg); color: var(--s-red-ink); }
.flash-success { background: var(--s-green-bg); color: var(--s-green-ink); }

/* ---- List cards (contracts, users, services) ---- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-card { display: flex; align-items: center; gap: 12px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 15px; color: var(--ink); }
a.list-card:hover { text-decoration: none; border-color: #cfd8e3; background: #fafbfd; }
.list-card.static { cursor: default; }
.lc-main { flex: 1; min-width: 0; }
.lc-title { font-weight: 600; }
.lc-sub { font-size: 13.5px; margin-top: 1px; }
.lc-meta { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; }
.lc-end { flex: none; }
.row-actions { flex: none; display: flex; gap: 6px; }

/* ---- Status badges ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; white-space: nowrap; }
/* contract */
.badge-draft { background: var(--s-grey-bg); color: var(--s-grey-ink); }
.badge-active { background: var(--s-green-bg); color: var(--s-green-ink); }
.badge-expiring { background: var(--s-amber-bg); color: var(--s-amber-ink); }
.badge-expired { background: var(--s-red-bg); color: var(--s-red-ink); }
.badge-closed { background: var(--s-mute-bg); color: var(--s-mute-ink); }
/* service */
.badge-upcoming { background: var(--s-grey-bg); color: var(--s-grey-ink); }
.badge-duesoon { background: var(--s-amber-bg); color: var(--s-amber-ink); }
.badge-scheduled { background: var(--s-blue-bg); color: var(--s-blue-ink); }
.badge-completed { background: var(--s-green-bg); color: var(--s-green-ink); }
.badge-overdue { background: var(--s-red-bg); color: var(--s-red-ink); }
.badge-cancelled { background: var(--s-mute-bg); color: var(--s-mute-ink); }

/* ---- Due indicators ---- */
.due { white-space: nowrap; }
.due::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; background: var(--border); vertical-align: middle; }
.due-overdue { color: var(--due-over); font-weight: 600; }
.due-overdue::before { background: var(--due-over); }
.due-due-soon { color: var(--due-soon); }
.due-due-soon::before { background: var(--due-soon); }
.due-closed { color: var(--muted); }

/* ---- Dashboard stat tiles ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; color: var(--ink); }
a.stat:hover { text-decoration: none; border-color: #cfd8e3; background: #fafbfd; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.8px; margin-top: 2px; }
.stat.accent-alert { border-left: 4px solid var(--due-over); }
.stat.accent-alert .n { color: var(--due-over); }
.stat.accent-warn { border-left: 4px solid var(--due-soon); }

/* ---- Toolbar / chips ---- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 160px; flex: 1 1 auto; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.chip { display: inline-block; padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--ink); font-size: 13.5px; font-weight: 600; }
.chip:hover { background: #eef3f9; text-decoration: none; }
.chip-on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.chip-on:hover { background: var(--brand); }

/* ---- Needs Attention ---- */
.attn-block { margin-bottom: 18px; }
.attn-head { font-weight: 700; font-size: 13.5px; padding: 6px 4px; display: flex; align-items: center; gap: 8px; }
.attn-head-alert { color: var(--due-over); }
.attn-head-warn { color: var(--due-soon); }
.attn-list { display: flex; flex-direction: column; gap: 6px; }
.attn-line { display: flex; align-items: center; gap: 12px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px; color: var(--ink); }
.attn-line:hover { text-decoration: none; border-color: #cfd8e3; background: #fafbfd; }
.attn-line-main { flex: 1; min-width: 0; }
.attn-line-title { font-weight: 600; display: block; }
.attn-line-sub { font-size: 13px; color: var(--muted); display: block; margin-top: 1px; }
.attn-line-end { flex: none; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chip-mini { display: inline-block; padding: 0 8px; border-radius: 999px; background: var(--border-2);
  color: var(--muted); font-size: 11.5px; font-weight: 600; }

/* ---- Detail ---- */
.detail-grid { display: grid; grid-template-columns: 1.7fr 1fr; gap: 18px; align-items: start; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; }
.section-title h2 { margin: 0; }
.na-fieldset { background: #fafbfd; }
.na-fieldset-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--brand); margin-bottom: 4px; }
.doclist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.doclist li { font-size: 13.8px; }
.empty { color: var(--muted); padding: 22px; text-align: center; }

/* ---- Activity timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { padding: 8px 0 8px 14px; border-left: 2px solid var(--border-2); position: relative; }
.tl-item::before { content: ""; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--brand-2); }
.tl-item.tl-service_completed::before { background: var(--ok); }
.tl-item.tl-contract_renewed::before { background: var(--s-blue-ink); }
.tl-item.tl-contract_activated::before { background: var(--s-green-ink); }
.tl-meta { font-size: 12px; color: var(--muted); }
.tl-note { font-size: 14px; }
.tl-label { font-weight: 600; }

/* ---- Work list (schedule + my work) ---- */
.work-section { margin-bottom: 18px; }
.work-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700;
  font-size: 14px; padding: 6px 12px; border-radius: 8px; margin-bottom: 8px; }
.work-count { background: rgba(0,0,0,.10); border-radius: 999px; padding: 0 9px; font-size: 12.5px; }
.work-overdue { background: var(--s-red-bg); color: var(--s-red-ink); }
.work-due-week { background: var(--s-amber-bg); color: var(--s-amber-ink); }
.work-upcoming { background: var(--s-grey-bg); color: var(--s-grey-ink); }
.work-list { display: flex; flex-direction: column; gap: 8px; }
.work-card { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 15px; }
.work-main { flex: 1; min-width: 0; }
.work-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.work-na-text { font-weight: 600; }
.work-cust { font-weight: 600; margin-top: 3px; }
.work-scope { font-size: 13px; margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.work-open { flex: none; display: flex; gap: 6px; align-items: center; }

/* ---- Switch System ---- */
.switch-system { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }
.switch-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 2px 12px 6px; }

/* ---- Responsive ---- */
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  .layout { flex-direction: column; min-height: 0; }
  .sidebar { flex: none; width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: 6px; border-right: none; border-bottom: 1px solid var(--border); padding: 9px 12px; }
  .sidenav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .switch-system { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding-top: 0; border-top: none; flex-direction: row; align-items: center; gap: 10px; }
  .sidenav-admin { width: auto; }
  .who { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .work-card, .list-card, .attn-line { flex-direction: column; align-items: stretch; }
  .work-open, .row-actions { width: 100%; }
  .work-open .btn, .row-actions .btn { width: 100%; }
  .lc-end, .attn-line-end { justify-content: flex-start; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .page-head .btn { width: 100%; }
}
@media (max-width: 420px) { .content { padding: 18px 14px; } }
