/* DMS v1.1 Client Portal - on-brand, WCAG-AA, responsive (no build step). */
:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --border: #cbd3e1;
  --border-strong: #9aa7bd;
  --text: #14203a;          /* ~14.5:1 on white */
  --text-muted: #4a5670;    /* ~6.6:1 on white */
  --primary: #17509e;       /* white text ~6.6:1 */
  --primary-ink: #0e356b;
  --danger: #a51f16;        /* white text ~6.8:1 */
  --danger-ink: #7c1710;
  --ok: #146c3f;            /* white text ~4.9:1 */
  --warn-bg: #fbeecb;
  --warn-ink: #6b4a05;      /* on warn-bg > 5:1 */
  --focus: #0b57d0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,32,58,.08), 0 6px 20px rgba(20,32,58,.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
img, svg, table { max-width: 100%; }

/* ---- focus visibility (keyboard) ---- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
  box-shadow: 0 0 0 5px rgba(11, 87, 208, .28);
}
.btn:focus-visible, .navlink:focus-visible { outline-color: #08306b; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0 0 0 0) !important; white-space: nowrap !important; border: 0 !important;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px clamp(12px, 3vw, 28px); box-shadow: var(--shadow);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-mark {
  background: var(--primary); color: #fff; font-weight: 800; font-size: 13px;
  padding: 4px 8px; border-radius: 7px; letter-spacing: .5px;
}
.brand-name { font-size: 1.05rem; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav[hidden] { display: none; }
.navlink {
  text-decoration: none; color: var(--text-muted); padding: 7px 12px; border-radius: 8px;
  font-weight: 600; font-size: .95rem;
}
.navlink:hover { background: var(--surface-2); color: var(--text); }
.navlink[aria-current="page"] { background: #e3ecfa; color: var(--primary-ink); }
.session { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.session-chip {
  display: inline-flex; align-items: center; gap: 6px; background: #e6f4ec; color: #0f5130;
  border: 1px solid #b9dcc7; padding: 4px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600;
}
.session-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

/* ---- layout ---- */
.main { flex: 1 0 auto; width: 100%; max-width: 1120px; margin: 0 auto; padding: clamp(14px, 3vw, 28px); }
.footer { text-align: center; color: var(--text-muted); font-size: .8rem; padding: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(14px, 2.5vw, 22px); margin-bottom: 18px;
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; flex-wrap: wrap; }
.page-title { font-size: clamp(1.25rem, 3.5vw, 1.6rem); margin: 0; }
.page-head-actions { display: flex; align-items: center; gap: 8px; }
.section-title { font-size: 1rem; margin: 18px 0 8px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.lead { font-size: 1.02rem; color: var(--text-muted); margin-top: 0; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); font-size: .92em; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- help button ---- */
.help-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--primary-ink); font-weight: 800; font-size: 1.05rem;
  cursor: pointer; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.help-btn:hover { background: #e3ecfa; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 9px 15px; border-radius: 9px; line-height: 1.2; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-ink); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .86rem; border-radius: 7px; }

/* ---- forms ---- */
.label { display: block; font-weight: 600; margin-bottom: 6px; }
.label.inline { display: inline-block; margin: 0 8px 0 0; }
.input, select.input {
  font: inherit; width: 100%; max-width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: #fff; color: var(--text); min-height: 42px;
}
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(165,31,22,.15); }
.hint { color: var(--text-muted); font-size: .85rem; margin: 6px 0 0; }
.field-err { color: var(--danger-ink); font-weight: 600; font-size: .88rem; margin: 6px 0 0; }
.form-error { color: var(--danger-ink); background: #fbe9e7; border: 1px solid #f0b7b1; padding: 10px 12px; border-radius: 8px; font-weight: 600; margin: 4px 0; }
.form-grid { display: grid; gap: 16px; max-width: 560px; }
.login-form { display: grid; gap: 6px; max-width: 420px; }
.login-card { max-width: 520px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input { width: auto; flex: 1 1 220px; min-width: 0; }

/* ---- tables ---- */
.table-scroll { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); position: sticky; top: 0; }
.data-table tbody tr:last-child td { border-bottom: none; }
.order-row { cursor: pointer; }
.order-row:hover { background: #eef4ff; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- definition list of fields ---- */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 22px; margin: 0; }
.field { border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.field-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); margin: 0 0 2px; }
.field-value { margin: 0; font-weight: 600; word-break: break-word; }

/* ---- badges ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; border: 1px solid transparent; }
.badge-new, .badge-active { background: #dde8fb; color: #0e356b; border-color: #b9cdf0; }
.badge-hold { background: var(--warn-bg); color: var(--warn-ink); border-color: #e5cd8f; }
.badge-canceled { background: #f6dedb; color: #7c1710; border-color: #e6b3ac; }
.badge-na { background: #e7eaf0; color: #3c455a; border-color: #cbd3e1; }

/* ---- banners ---- */
.banner { padding: 12px 14px; border-radius: 9px; margin-bottom: 14px; font-weight: 600; border: 1px solid; }
.banner-ok { background: #e6f4ec; border-color: #b9dcc7; color: #0f5130; }
.banner-warn { background: var(--warn-bg); border-color: #e5cd8f; color: var(--warn-ink); }

/* ---- states: loading / empty / error / skeleton ---- */
.loading { display: flex; align-items: center; gap: 10px; padding: 22px; color: var(--text-muted); font-weight: 600; }
.spinner { width: 20px; height: 20px; border: 3px solid #c9d3e6; border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.state { text-align: center; padding: 30px 18px; }
.state-icon { width: 42px; height: 42px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.2rem; margin-bottom: 10px; }
.state-empty .state-icon { background: #e3ecfa; color: var(--primary-ink); }
.state-error .state-icon { background: #f6dedb; color: var(--danger-ink); }
.state-title { font-weight: 700; font-size: 1.05rem; margin: 0 0 4px; }
.state-msg { color: var(--text-muted); margin: 0 auto 12px; max-width: 46ch; }
.state-meta { color: var(--text-muted); font-size: .8rem; font-family: var(--mono); margin: 6px 0; }
.skel-row td { padding: 12px; }
.skel { height: 12px; border-radius: 6px; background: linear-gradient(90deg, #e7ecf4 25%, #f2f5fa 37%, #e7ecf4 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* ---- pager ---- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pager-info { color: var(--text-muted); font-size: .9rem; }
.pager-btns { display: flex; gap: 8px; }
.filter-note { font-size: .82rem; margin: 10px 0 0; }

/* ---- detail ---- */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.detail-num { margin: 0 10px 0 0; display: inline; font-size: 1.35rem; }
.detail-actions { margin-top: 18px; }

/* ---- 404 ---- */
.notfound-card { text-align: center; }
.notfound-code { font-size: clamp(3rem, 12vw, 5rem); font-weight: 800; color: var(--primary); line-height: 1; }
.notfound-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* ---- modal / help overlay / confirm ---- */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(10,20,40,.4);
  width: min(600px, 96vw); max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-title { margin: 0; font-size: 1.15rem; }
.modal-x { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--text); }
.modal-x:hover { background: var(--surface-2); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.help-intro { margin-top: 0; color: var(--text-muted); }
.help-list { display: grid; gap: 12px; margin: 0; }
.help-item { display: grid; gap: 2px; }
.help-term { font-weight: 700; margin: 0; }
.help-desc { margin: 0; color: var(--text-muted); }

/* ---- toasts ---- */
.toast-region { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 150; display: flex; flex-direction: column; gap: 8px; width: min(520px, 94vw); }
.toast {
  display: flex; align-items: center; gap: 12px; background: #14203a; color: #fff;
  padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.3);
  animation: toastin .18s ease-out;
}
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }
.toast-out { opacity: 0; transition: opacity .2s; }
.toast-ok { background: #0f5130; }
.toast-err { background: #7c1710; }
.toast-msg { flex: 1; font-weight: 600; }
.toast-action { background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.5); padding: 5px 12px; border-radius: 7px; font: inherit; font-weight: 700; cursor: pointer; }
.toast-action:hover { background: rgba(255,255,255,.28); }
.toast-close { background: transparent; color: #fff; border: none; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 4px; }

@media (max-width: 520px) {
  .page-head { align-items: flex-start; }
  .session-chip .session-label { display: none; }
  .modal-foot { justify-content: stretch; }
  .modal-foot .btn { flex: 1 1 auto; }
}
