/* TSMS — simple, clean admin UI. Light theme. */
:root {
  --bg: #f5f4f8;
  --surface: #ffffff;
  --surface-2: #faf9fc;
  --border: #e4e1ec;
  --text: #1f1a2b;
  --muted: #6b6478;
  --primary: #5a2d8c;
  --primary-ink: #ffffff;
  --primary-soft: #efe8f7;
  --ok: #1d7a46; --ok-soft: #e3f4ea;
  --warn: #8a5a00; --warn-soft: #fff1d6;
  --bad: #b42318; --bad-soft: #fde8e6;
  --info: #1d5fa8; --info-soft: #e5eefa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 26, 43, .06), 0 1px 1px rgba(31, 26, 43, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.nowrap { white-space: nowrap; }
body.modal-open { overflow: hidden; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 38px; padding: .45rem .95rem; border-radius: 8px; border: 1px solid transparent;
  font: 600 .9rem/1.2 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn-sm { min-height: 30px; padding: .25rem .65rem; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: #cfc9dc; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger-ghost { background: var(--surface); color: var(--bad); border-color: #f1c4bf; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-size: .85rem; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--bad); }
.icon-btn { background: none; border: 0; font-size: 1.1rem; cursor: pointer; padding: .35rem .5rem; border-radius: 6px; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.row-actions { white-space: nowrap; }
.row-actions > * + * { margin-left: .75rem; }

/* ---------- public layout ---------- */
.layout-public { min-height: 100vh; display: flex; flex-direction: column; }
.pub-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .75rem max(16px, calc((100% - 1100px) / 2)); background: var(--surface); border-bottom: 1px solid var(--border);
}
.pub-nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.pub-nav a { padding: .45rem .8rem; border-radius: 8px; color: var(--text); font-weight: 500; }
.pub-nav a:hover { background: var(--surface-2); text-decoration: none; }
.pub-nav a.active { background: var(--primary-soft); color: var(--primary); }
.pub-main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.pub-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.25rem 16px; border-top: 1px solid var(--border); background: var(--surface); }

.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none !important; }
.brand b { display: block; font-size: 1.05rem; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); font-size: .75rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}

.hero { padding: 2.25rem 0 1.5rem; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); max-width: 22ch; }
.eyebrow { color: var(--primary); font-weight: 700; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .5rem; }
.lead { font-size: 1.05rem; color: var(--muted); max-width: 60ch; }
.hero-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.25rem; }
.grid-home { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; align-items: start; }

/* ---------- app layout ---------- */
.layout-app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { padding: .25rem .5rem 1rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; justify-content: space-between; padding: .5rem .75rem; border-radius: 8px;
  color: var(--text); font-weight: 500; font-size: .92rem;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.nav-section { margin: 1rem .75rem .35rem; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.count { background: var(--bad); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700; padding: 0 .45rem; line-height: 1.4rem; min-width: 1.4rem; text-align: center; }
.app-body { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar-spacer { flex: 1; }
.menu-btn { display: none; }
.bell { position: relative; font-size: 1.1rem; text-decoration: none !important; padding: .25rem .4rem; }
.bell .count { position: absolute; top: -4px; right: -8px; }
.user-chip { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.user-chip small { color: var(--muted); font-size: .75rem; }
.app-main { padding: 1.5rem; max-width: 1280px; width: 100%; }

/* ---------- page parts ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.15rem; margin-bottom: 1rem; }
.card-title { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.card-danger { border-color: #f1c4bf; }
.stat-card { display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-weight: 600; font-size: .85rem; margin: 0; }
.stat-value { font-size: 2.6rem; font-weight: 750; line-height: 1.1; margin: .2rem 0 .3rem; color: var(--primary); font-variant-numeric: tabular-nums; }
.link-card { color: inherit; text-decoration: none !important; }
.link-card:hover { border-color: #cfc9dc; }
.link-arrow { margin-top: auto; font-weight: 600; font-size: .9rem; }
.grid-dash { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; align-items: start; }
.grid-detail > .card { margin-bottom: 0; }
.grid-detail + .card, .grid-detail + section { margin-top: 1rem; }
.grid-1 { display: grid; gap: .75rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.field-full { grid-column: 1 / -1; }

.dl { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: .45rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.notice { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: .65rem .85rem; margin-bottom: 1rem; font-size: .9rem; }
.notice-bad { background: var(--bad-soft); color: var(--bad); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.empty { color: var(--muted); padding: 1rem; text-align: center; font-size: .9rem; }
.empty-page { text-align: center; padding: 3rem 1rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.15rem; padding: 0 1.15rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: .55rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td:first-child { white-space: nowrap; }
.table tfoot td { border-top: 2px solid var(--border); border-bottom: 0; font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.loc-table .bar-col { width: 45%; }
.bar { display: block; height: 10px; border-radius: 5px; background: var(--primary); opacity: .75; min-width: 4px; margin-top: .45rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.filters input[type=search] { flex: 1 1 240px; }
.filters select { flex: 0 1 200px; }

/* ---------- badges, chips ---------- */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 650; white-space: nowrap; vertical-align: middle; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eeecf2; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { display: inline-flex; gap: .4rem; align-items: center; padding: .35rem .75rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: .85rem; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-label { font-size: .85rem; font-weight: 600; }
.field-hint { font-size: .78rem; color: var(--muted); }
.req { color: var(--bad); font-weight: 700; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid #cfc9dc; border-radius: 8px; padding: .5rem .65rem; min-height: 38px;
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; }
input[type=file] { padding: .4rem; }
input[type=checkbox] { width: auto; min-height: 0; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.form-error { color: var(--bad); background: var(--bad-soft); padding: .5rem .7rem; border-radius: 8px; font-size: .88rem; margin: .5rem 0 0; }
.form-error[hidden] { display: none; }
.form-section { margin: 1.25rem 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.copy-row { display: flex; gap: .5rem; margin-bottom: .75rem; }

/* ---------- auth ---------- */
.auth-wrap { display: flex; justify-content: center; padding: 1.5rem 0; }
.auth-card { width: 100%; max-width: 420px; }
.auth-wrap.wide .auth-card { max-width: 720px; }
.auth-card form { display: grid; gap: .8rem; margin: 1rem 0; }
.auth-card form.grid-2 { grid-template-columns: 1fr 1fr; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 14, 30, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-wide { max-width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.15rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1.15rem; display: grid; gap: .75rem; }
.modal-body .table-wrap { margin: 0; padding: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .85rem 1.15rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }

/* ---------- toast ---------- */
#toast-host { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 60; max-width: calc(100% - 32px); }
.toast { background: #1f1a2b; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); font-size: .9rem; transition: opacity .3s, transform .3s; border-left: 4px solid #4cc17f; }
.toast-bad { border-left-color: #f0645a; }
.toast-warn { border-left-color: #f2b13a; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- documents ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.gallery figcaption { font-size: .8rem; color: var(--muted); margin-top: .25rem; overflow-wrap: anywhere; }
.doc-list, .plain-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; flex-wrap: wrap; gap: .25rem .6rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.doc-list li:last-child { border-bottom: 0; }
.doc-type { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .35rem; }
.plain-list li { padding: .35rem 0; }

/* ---------- work order ---------- */
.stepper { list-style: none; display: flex; padding: 0; margin: 0 0 1rem; gap: 4px; overflow-x: auto; }
.stepper li { flex: 1; min-width: 100px; text-align: center; padding: .5rem .25rem; font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.stepper li:first-child { border-radius: 8px 0 0 8px; }
.stepper li:last-child { border-radius: 0 8px 8px 0; }
.stepper li.done { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.stepper li.current { background: var(--primary); color: #fff; border-color: transparent; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--border); padding: 0 0 1rem 1rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline li:last-child { padding-bottom: 0; }
.tl-head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .25rem; }

/* ---------- notifications ---------- */
.notif-list { list-style: none; margin: 0 -1.15rem; padding: 0; }
.notif-list li { border-bottom: 1px solid var(--border); }
.notif-list li:last-child { border-bottom: 0; }
.notif { display: flex; flex-direction: column; gap: .15rem; width: 100%; text-align: left; background: none; border: 0; padding: .8rem 1.15rem; cursor: pointer; font: inherit; color: inherit; }
.notif:hover { background: var(--surface-2); }
.notif-title { font-weight: 650; }
.notif-msg { font-size: .9rem; }
.unread .notif { background: var(--primary-soft); }
.unread .notif-title::before { content: "● "; color: var(--primary); }

.prose ul { padding-left: 1.2rem; }
.prose li { margin-bottom: .35rem; }
.prose h2 { margin-top: 1.25rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout-app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0, 0, 0, .15); }
  .layout-app.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-block; }
  .app-main { padding: 1rem 16px; }
  .topbar { padding: .5rem 16px; }
  .grid-dash, .grid-home { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .auth-card form.grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .user-chip { display: none; }
  .table-wrap { margin: 0 -1.15rem; }
  .dl { grid-template-columns: 1fr; gap: .1rem; }
  .dl dd { margin-bottom: .5rem; }
  .page-head .actions { width: 100%; }
  .loc-table .bar-col { display: none; }
}
