:root {
  --navy: #0b1f3a;
  --navy-2: #112b4d;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --teal: #14b8a6;
  --ink: #172033;
  --muted: #65738a;
  --line: #dce3ec;
  --surface: #ffffff;
  --canvas: #f3f6fa;
  --soft-blue: #eff6ff;
  --success: #087c60;
  --warning: #9a5b00;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(11, 31, 58, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 16px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.auth-shell { min-height: 100vh; background: radial-gradient(circle at 15% 15%, rgba(20,184,166,.2), transparent 25%), linear-gradient(135deg, #08182e 0%, #102d50 58%, #174465 100%); }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.auth-card { width: min(100%, 460px); background: var(--surface); border-radius: 20px; padding: 42px; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.auth-brand { margin-bottom: 24px; }
.auth-card h1 { margin: 4px 0 10px; font-size: clamp(1.8rem, 5vw, 2.35rem); line-height: 1.15; letter-spacing: -.035em; }
.auth-note { margin: 22px 0 0; color: var(--muted); font-size: .875rem; text-align: center; }

.topbar { height: 76px; padding: 0 max(24px, calc((100vw - 1440px)/2)); background: var(--navy); color: white; display: grid; grid-template-columns: 230px 1fr auto; align-items: center; gap: 30px; position: sticky; top: 0; z-index: 20; box-shadow: 0 3px 18px rgba(11,31,58,.18); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: white; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; background: var(--teal); color: var(--navy); font-weight: 900; font-size: 1.25rem; }
.brand-mark.large { width: 52px; height: 52px; border-radius: 13px; font-size: 1.65rem; }
.brand > span:last-child { display: grid; line-height: 1; }
.brand small { margin-top: 5px; color: #9fb2ca; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; }
.topnav { height: 100%; display: flex; align-items: stretch; gap: 6px; }
.topnav a { color: #c9d5e4; display: flex; align-items: center; padding: 0 18px; border-bottom: 3px solid transparent; font-weight: 600; }
.topnav a:hover, .topnav a.active { color: white; text-decoration: none; border-bottom-color: var(--teal); background: rgba(255,255,255,.035); }
.account { display: flex; align-items: center; gap: 14px; font-size: .875rem; color: #c9d5e4; }
.account form { margin: 0; }
.link-button { border: 0; background: none; color: white; cursor: pointer; padding: 6px; }

.page { max-width: 1440px; margin: 0 auto; padding: 42px max(24px, 4vw) 70px; }
.page-heading { margin-bottom: 30px; }
.page-heading h1 { margin: 4px 0 6px; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.08; letter-spacing: -.04em; color: var(--navy); }
.page-heading p:not(.eyebrow) { color: var(--muted); margin: 0; }
.split-heading, .ticket-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; }
.eyebrow { color: var(--blue-dark); font-size: .78rem; letter-spacing: .13em; font-weight: 800; margin: 0; }
.muted { color: var(--muted); }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; color: var(--navy); font-size: 1.25rem; }
.section-heading > span { color: var(--muted); font-size: .875rem; }
.section-space { margin-top: 42px; }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 9px; padding: 10px 17px; font-weight: 750; cursor: pointer; transition: transform .15s, box-shadow .15s, background .15s; }
.button:hover { text-decoration: none; transform: translateY(-1px); }
.button.primary { background: var(--blue); color: white; box-shadow: 0 7px 16px rgba(37,99,235,.2); }
.button.primary:hover { background: var(--blue-dark); }
.button.secondary { background: white; color: var(--navy); border-color: #b9c6d7; }
.button.warning { background: #fff7e6; border-color: #edcc8b; color: #764600; }
.wide { width: 100%; }

.form-stack { display: grid; gap: 10px; }
.form-stack label, .reply-box label { font-weight: 720; color: var(--navy); margin-top: 7px; }
input, select, textarea { width: 100%; border: 1px solid #b9c6d7; border-radius: 9px; padding: 12px 13px; color: var(--ink); background: white; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(37,99,235,.18); border-color: var(--blue); }
textarea { resize: vertical; }
.otp { text-align: center; letter-spacing: .45em; font-size: 1.55rem; font-weight: 800; }
.form-page { width: min(100%, 780px); margin: 0 auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }

.panel, .table-card, .ticket-list, .detail-strip, .reply-box { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.panel { padding: 24px; }
.installation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.installation-card { color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 20px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; box-shadow: 0 4px 20px rgba(11,31,58,.045); transition: border-color .16s, transform .16s, box-shadow .16s; }
.installation-card:hover { text-decoration: none; border-color: #9cb8db; transform: translateY(-2px); box-shadow: var(--shadow); }
.installation-icon { width: 50px; height: 50px; border-radius: 12px; background: var(--soft-blue); color: var(--blue-dark); display: grid; place-items: center; font-size: 1.2rem; font-weight: 850; }
.installation-content h3 { margin: 0 0 3px; color: var(--navy); }
.installation-content p { margin: 0; color: var(--muted); }
.meta-row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 10px; font-size: .78rem; color: var(--muted); }
.meta-row span { background: #f1f4f8; border-radius: 999px; padding: 3px 8px; }
.chevron { font-size: 1.8rem; color: #8da0b7; }

.table-card { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { padding: 13px 16px; background: #f7f9fc; color: #59677c; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; text-align: left; border-bottom: 1px solid var(--line); }
td { padding: 15px 16px; border-bottom: 1px solid #ebeff4; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr[data-href] { cursor: pointer; }
tbody tr[data-href]:hover { background: #f8fbff; }
td small { display: block; color: var(--muted); margin-top: 2px; }

.status, .priority, .reason { display: inline-flex; align-items: center; white-space: nowrap; border-radius: 999px; padding: 4px 9px; font-weight: 750; font-size: .76rem; }
.status-open { color: #174ea6; background: #e8f0fe; }
.status-in_progress { color: #775100; background: #fff4d2; }
.status-waiting_customer { color: #6d3cb0; background: #f2eaff; }
.status-closed { color: #506174; background: #e9eef3; }
.large-status { font-size: .875rem; padding: 7px 12px; }
.priority-normal, .priority-low { color: #506174; background: #edf1f5; }
.priority-high { color: #9a5b00; background: #fff3d6; }
.priority-urgent { color: var(--danger); background: #ffebe9; }

.empty-state { text-align: center; background: white; border: 1px dashed #b9c6d7; border-radius: 13px; padding: 56px 24px; }
.empty-state.compact { padding: 34px 20px; }
.empty-state h3 { margin: 0 0 5px; color: var(--navy); }
.empty-state p { margin: 0; color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 20px; font-weight: 650; }

.notice { padding: 12px 15px; border-radius: 9px; margin: 0 0 18px; border: 1px solid; }
.notice.success { color: #066b52; background: #eafaf5; border-color: #a8e6d2; }
.notice.info { color: #174ea6; background: #edf5ff; border-color: #bdd6f7; }
.notice.error { color: #9f1c14; background: #fff0ee; border-color: #f0b7b2; }

.detail-strip { display: grid; grid-template-columns: repeat(3, 1fr); overflow: hidden; }
.detail-strip div { padding: 20px 24px; border-right: 1px solid var(--line); }
.detail-strip div:last-child { border-right: 0; }
.detail-strip span { display: block; color: var(--muted); font-size: .8rem; margin-bottom: 4px; }
.ticket-list { overflow: hidden; }
.ticket-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 17px 20px; border-bottom: 1px solid var(--line); color: var(--ink); }
.ticket-row:last-child { border: 0; }
.ticket-row:hover { background: #f8fbff; text-decoration: none; }
.ticket-row div { display: grid; }
.ticket-row span:not(.status) { color: var(--muted); font-size: .82rem; }

.conversation { display: grid; gap: 13px; }
.message { width: min(88%, 820px); border: 1px solid var(--line); border-radius: 13px; padding: 17px 19px; background: white; }
.message.customer-message { justify-self: start; border-left: 4px solid var(--teal); }
.message.agent-message { justify-self: end; background: var(--soft-blue); border-color: #c9dcf5; border-right: 4px solid var(--blue); }
.message.internal-message { justify-self: center; background: #fff8e8; border-color: #edd9a4; }
.message header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.message time { color: var(--muted); font-size: .78rem; margin-left: auto; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.source-label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.attachments { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments a, .attachments span { background: rgba(255,255,255,.75); border: 1px solid #c8d4e2; border-radius: 7px; padding: 6px 9px; font-size: .82rem; }
.reply-box { margin-top: 18px; padding: 20px; display: grid; gap: 10px; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.reply-actions span { color: var(--muted); font-size: .82rem; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metric { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; color: var(--ink); }
.metric:hover { text-decoration: none; border-color: #9cb8db; }
.metric span { color: var(--muted); }
.metric strong { font-size: 1.8rem; color: var(--navy); }
.metric.urgent { border-left: 4px solid #e34b42; }
.agent-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; align-items: start; gap: 24px; }
.ticket-sidebar { display: grid; gap: 16px; position: sticky; top: 96px; }
.compact-form h2, .facts h2 { font-size: 1.05rem; margin: 0 0 4px; color: var(--navy); }
.facts dl { margin: 14px 0 0; display: grid; gap: 3px; }
.facts dt { color: var(--muted); font-size: .78rem; margin-top: 10px; }
.facts dd { margin: 0; }
.heading-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 12px; }
.robaws-link { font-size: .85rem; color: var(--success); font-weight: 700; }

.unlinked-list { display: grid; gap: 14px; }
.unlinked-card header { display: flex; justify-content: space-between; gap: 18px; }
.unlinked-card header div { display: grid; }
.unlinked-card header span, .unlinked-card time { color: var(--muted); font-size: .82rem; }
.unlinked-card .reason { margin-top: 13px; background: #fff3d6; color: #775100; }
.unlinked-card p { margin-bottom: 0; white-space: pre-wrap; }
.inline-form { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.inline-form label { display: block; color: var(--navy); font-weight: 700; margin-bottom: 6px; }
.inline-form > div { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 18px; }
  .topnav { position: fixed; bottom: 0; left: 0; right: 0; height: 64px; background: var(--navy); justify-content: center; z-index: 30; box-shadow: 0 -4px 18px rgba(11,31,58,.15); }
  .topnav a { padding: 0 22px; border-top: 3px solid transparent; border-bottom: 0; }
  .topnav a.active { border-top-color: var(--teal); }
  .account > span { display: none; }
  .page { padding-bottom: 92px; }
  .installation-grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .agent-layout { grid-template-columns: 1fr; }
  .ticket-sidebar { position: static; grid-row: 1; }
}

@media (max-width: 620px) {
  .auth-card { padding: 30px 22px; border-radius: 15px; }
  .page { padding: 28px 16px 90px; }
  .split-heading, .ticket-heading { align-items: stretch; flex-direction: column; }
  .split-heading .button { width: 100%; }
  .page-heading h1 { font-size: 2rem; }
  .detail-strip { grid-template-columns: 1fr; }
  .detail-strip div { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-strip div:last-child { border-bottom: 0; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { padding: 14px; display: grid; }
  .metric strong { font-size: 1.5rem; }
  .message { width: 100%; }
  .reply-actions { align-items: stretch; flex-direction: column; }
  .reply-actions .button { width: 100%; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .ticket-row { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
