:root {
  --navy-950: #050a11;
  --navy-900: #08121f;
  --navy-800: #102a49;
  --blue-600: #087fc9;
  --blue-500: #16a8f4;
  --cyan-500: #16a6b6;
  --green-600: #16815d;
  --amber-600: #b96f12;
  --amber-500: #f0a33a;
  --red-600: #b53636;
  --ink: #172331;
  --muted: #627184;
  --line: #d8e0e8;
  --line-strong: #bcc9d5;
  --surface: #ffffff;
  --surface-soft: #f4f7fa;
  --surface-raised: #eef3f7;
  --shadow: 0 8px 24px rgba(18, 38, 60, .10);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--surface-soft); color: var(--ink); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--blue-600); }
[hidden] { display: none !important; }

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 38%) 1fr;
  background: var(--surface);
}

.auth-brand {
  background: var(--navy-950);
  color: #fff;
  padding: clamp(32px, 6vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
}

.auth-brand img.brand-lockup { width: min(360px, 100%); height: auto; display: block; }
.auth-brand h1 { margin: 28px 0 8px; font-size: clamp(28px, 3vw, 42px); line-height: 1.08; }
.auth-brand p { margin: 0; color: #b8c8da; max-width: 420px; }
.auth-brand small { color: #8298b1; }
.auth-main { display: grid; place-items: center; padding: 28px; }
.auth-panel { width: min(440px, 100%); }
.auth-panel h2 { margin: 0 0 6px; font-size: 24px; }
.auth-panel > p { color: var(--muted); margin: 0 0 22px; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  padding: 3px;
  margin-bottom: 22px;
  border-radius: 6px;
}
.segmented button { border: 0; background: transparent; padding: 9px; color: var(--muted); border-radius: 4px; }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(17, 35, 52, .12); font-weight: 650; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { font-size: 13px; color: #46576a; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 5px;
  padding: 10px 11px;
  min-height: 42px;
  outline: none;
}
textarea { min-height: 112px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(46, 155, 255, .14); }

.btn {
  border: 1px solid transparent;
  border-radius: 5px;
  min-height: 40px;
  padding: 8px 14px;
  background: var(--blue-600);
  color: #fff;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; border-color: var(--line-strong); color: var(--ink); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--blue-600); padding-inline: 8px; }
.btn.danger { background: var(--red-600); }
.btn.success { background: var(--green-600); }
.btn.warning { background: var(--amber-600); }
.btn.full { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }

.notice { border-left: 4px solid var(--blue-500); background: #edf7ff; padding: 12px 14px; color: #234862; margin: 14px 0; }
.notice.error { border-color: var(--red-600); background: #fff0f0; color: #7f2626; }
.notice.success { border-color: var(--green-600); background: #eaf8f2; color: #175d48; }
.pin-input { font-size: 26px; font-weight: 750; text-align: center; letter-spacing: 8px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { background: var(--navy-900); color: #fff; min-height: 100vh; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 7px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side-brand img { width: 48px; height: 48px; object-fit: cover; border: 1px solid rgba(255,255,255,.16); border-radius: 6px; }
.side-brand strong { display: block; font-size: 15px; }
.side-brand span { display: block; font-size: 12px; color: var(--amber-500); }
.side-nav { display: grid; gap: 5px; margin-top: 18px; }
.side-nav button { border: 0; background: transparent; color: #b9c8d8; text-align: left; padding: 10px 11px; border-radius: 5px; font-weight: 600; }
.side-nav button:hover, .side-nav button.active { background: var(--navy-800); color: #fff; }
.sidebar-footer { position: absolute; bottom: 18px; left: 14px; right: 14px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 13px; }
.sidebar-footer .user { font-size: 13px; margin-bottom: 8px; overflow-wrap: anywhere; }
.sidebar-footer .user span { color: #9fb2c8; display: block; font-size: 12px; }

.workspace { min-width: 0; }
.topbar { min-height: 68px; background: #fff; border-bottom: 1px solid var(--line); padding: 13px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.content { padding: 22px 24px 40px; max-width: 1500px; margin: 0 auto; }

.toolbar { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.filters { display: flex; gap: 9px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 150px; min-height: 38px; padding-block: 7px; }
.filters input[type="search"] { min-width: 260px; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 1px 2px rgba(18, 38, 60, .04); }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 16px; }
.panel-body { padding: 16px; }
.empty { text-align: center; color: var(--muted); padding: 42px 20px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.data-table td { padding: 12px; border-bottom: 1px solid #e8edf2; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr[data-action] { cursor: pointer; }
.data-table tbody tr[data-action]:hover { background: #f2f7fb; }
.data-table .number { font-weight: 700; color: var(--blue-600); white-space: nowrap; }
.table-scroll { overflow-x: auto; }

.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #e8eef4; color: #405269; }
.pill.new, .pill.assigned { background: #e8f4ff; color: #12649f; }
.pill.in_progress, .pill.review { background: #e7f7f8; color: #0d737e; }
.pill.waiting_customer, .pill.waiting_internal { background: #fff3dc; color: #8a5709; }
.pill.resolved, .pill.approved, .pill.active, .pill.exported { background: #e6f6ee; color: #126445; }
.pill.closed, .pill.cancelled, .pill.not_billable { background: #edf0f3; color: #5e6874; }
.pill.urgent { background: #ffe7e7; color: #9c2d2d; }
.pill.high { background: #fff0dc; color: #8d5506; }

.split-view { display: grid; grid-template-columns: minmax(320px, .9fr) minmax(460px, 1.4fr); gap: 16px; align-items: start; }
.split-view > * { min-width: 0; }
.ticket-list { max-height: calc(100vh - 190px); overflow: auto; }
.ticket-row { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: #fff; text-align: left; padding: 13px 14px; color: var(--ink); }
.ticket-row:hover, .ticket-row.active { background: #eef6fc; }
.ticket-row strong { display: block; margin: 4px 0; line-height: 1.3; }
.ticket-row .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.ticket-detail { min-height: 420px; }
.detail-title h2 { margin: 0 0 5px; font-size: 20px; }
.detail-title .meta { color: var(--muted); font-size: 13px; display: flex; gap: 12px; flex-wrap: wrap; }
.detail-section { border-top: 1px solid var(--line); padding: 16px; }
.detail-section h3 { margin: 0 0 12px; font-size: 14px; }
.description { white-space: pre-wrap; line-height: 1.6; }

.timeline { display: grid; gap: 10px; }
.message { border-left: 3px solid var(--blue-500); padding: 9px 12px; background: #f7fafc; }
.message.internal { border-color: var(--amber-600); background: #fff8ec; }
.message .message-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.message p { margin: 0; white-space: pre-wrap; }

.attachment-list { display: grid; gap: 7px; }
.attachment-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); padding: 9px 10px; border-radius: 5px; background: #f8fafc; }
.attachment-row a { font-weight: 650; text-decoration: none; overflow-wrap: anywhere; }
.attachment-row span:not(.pill) { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.attachment-form { display: flex; align-items: end; gap: 9px; margin-top: 12px; }
.attachment-item { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; margin-bottom: 10px; }
.attachment-preview { display: block; width: 100%; max-height: 520px; object-fit: contain; background: #f3f6f9; border: 0; }
.attachment-preview.pdf { height: 520px; }
.attachment-item .attachment-row { border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.camera-button { cursor: pointer; white-space: nowrap; }
.site-visit-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; background: #eef7f3; border-bottom: 1px solid var(--line); }
.site-visit-bar span { display: block; color: var(--muted); font-size: 12px; }
.site-visit-bar strong { display: block; margin-top: 3px; }
.btn.danger { background: #a33a3a; color: #fff; }
.attachment-form .field { flex: 1; margin: 0; }
.empty.compact { padding: 14px; }

.work-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.metric-strip { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.metric { padding: 14px 16px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 3px; }

.portal-shell { min-height: 100vh; }
.portal-header { min-height: 72px; background: var(--navy-900); color: #fff; padding: 12px max(20px, calc((100vw - 1180px)/2)); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.portal-brand { display: flex; align-items: center; gap: 11px; }
.portal-brand img { width: 54px; height: 54px; object-fit: cover; border: 1px solid rgba(255,255,255,.16); border-radius: 6px; }
.portal-brand strong { display: block; }
.portal-brand span { display: block; color: #b7c6d6; font-size: 12px; }
.portal-main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 44px; }
.portal-summary { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.portal-summary h1 { margin: 0; font-size: 24px; }
.portal-summary p { margin: 4px 0 0; color: var(--muted); }

dialog { border: 0; border-radius: 7px; padding: 0; width: min(620px, calc(100% - 28px)); box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(7, 17, 31, .55); }
.dialog-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.check-row { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 600; }
.check-row input { width: 18px; height: 18px; min-height: 0; margin: 0; }
.icon-btn { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); font-size: 22px; border-radius: 4px; }
.icon-btn:hover { background: var(--surface-raised); color: var(--ink); }

.loading { color: var(--muted); padding: 14px; }
.mut { color: var(--muted); font-size: 12px; margin-top: 3px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; background: var(--navy-950); color: #fff; padding: 11px 14px; border-radius: 5px; box-shadow: var(--shadow); max-width: min(380px, calc(100vw - 36px)); }
.toast.error { background: #872c2c; }

@media (max-width: 980px) {
  .split-view { grid-template-columns: 1fr; }
  .ticket-list { max-height: 380px; }
  .work-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-page { display: block; }
  .auth-brand { min-height: auto; padding: 24px; }
  .auth-brand img.brand-lockup { width: min(220px, 72vw); }
  .auth-brand h1 { font-size: 26px; margin-top: 16px; }
  .auth-brand small { display: none; }
  .auth-main { padding: 26px 18px 40px; }
  .app-shell { display: block; }
  .sidebar { position: static; min-height: auto; height: auto; padding: 10px 12px; }
  .side-brand { border: 0; padding-bottom: 8px; }
  .side-nav { display: flex; overflow-x: auto; margin: 0; padding-bottom: 4px; }
  .side-nav button { white-space: nowrap; }
  .sidebar-footer { position: static; display: flex; align-items: center; justify-content: space-between; padding-top: 8px; }
  .sidebar-footer .user { margin: 0; }
  .topbar { position: static; padding: 12px 16px; }
  .topbar-actions { flex-shrink: 0; }
  .content, .portal-main { padding: 16px 12px 34px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .filters { width: 100%; }
  .filters input, .filters select, .filters input[type="search"] { width: 100%; min-width: 0; }
  .portal-header { padding: 10px 14px; }
  .portal-summary { align-items: flex-start; }
  .metric-strip { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .ticket-row { max-width: 100%; overflow: hidden; }
  .ticket-row .meta > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .attachment-form { align-items: stretch; flex-direction: column; }
  .attachment-preview.pdf { height: 420px; }
  .site-visit-bar { position: sticky; top: 0; z-index: 4; }
}
