:root {
    --bg: #f4f7f9;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --muted: #7b879c;
    --line: #e6ebf1;
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --primary-soft: #e5f6fd;
    --green: #16a66a;
    --green-soft: #e7f8ef;
    --orange: #e9892f;
    --orange-soft: #fff3e7;
    --red: #e34d59;
    --red-soft: #fdebed;
    --shadow: 0 12px 34px rgba(25, 39, 64, .06);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 18px 18px; background: var(--surface); border-right: 1px solid var(--line); z-index: 20; }
.brand { display: inline-flex; align-items: center; gap: 11px; padding: 2px 9px 26px; font-size: 19px; letter-spacing: -.4px; }
.brand span:last-child { display: flex; }
.brand strong { font-weight: 800; }
.brand em { color: var(--primary); font-style: normal; font-weight: 800; }
.brand-mark { width: 38px; height: 38px; display: inline-grid; place-items: center; color: white; background: var(--primary); border-radius: 11px; box-shadow: 0 8px 18px rgba(14, 165, 233, .24); font-size: 19px; }
.sidebar-nav { display: grid; gap: 6px; }
.sidebar-nav a { display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 14px; color: #5f6c80; border-radius: 12px; font-size: 14px; font-weight: 600; }
.sidebar-nav a i { width: 20px; font-size: 18px; }
.sidebar-nav a:hover { background: var(--surface-soft); color: var(--text); }
.sidebar-nav a.active { color: var(--primary-dark); background: var(--primary-soft); }
.sidebar-user { margin-top: auto; min-width: 0; padding: 11px; display: grid; grid-template-columns: 38px minmax(0, 1fr) 34px; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 14px; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: #fff; background: #1f314c; font-weight: 700; }
.sidebar-user > span:nth-child(2) { min-width: 0; display: grid; }
.sidebar-user strong { overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.sidebar-user small { color: var(--muted); margin-top: 2px; font-size: 11px; }
.sidebar-user form { margin: 0; }

.workspace { min-width: 0; }
.topbar { height: 72px; position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 18px; padding: 0 28px; background: rgba(255,255,255,.95); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.global-search { width: min(480px, 48vw); height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 15px; border: 1px solid var(--line); background: var(--surface-soft); border-radius: 12px; }
.global-search i { color: #91a0b5; }
.global-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.global-search input::placeholder { color: #9aa6b8; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.status-dot { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 600; }
.status-dot i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 10px; color: #627086; background: var(--surface); cursor: pointer; }
.icon-button:hover { border-color: #ccd7e3; color: var(--primary-dark); }
.mobile-menu { display: none; }
.page { padding: 30px; }
.page-heading, .detail-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-heading.compact { align-items: center; }
.page-heading h1, .detail-heading h1 { margin: 3px 0 6px; font-size: clamp(25px, 2.4vw, 34px); line-height: 1.12; letter-spacing: -.8px; }
.page-heading p, .detail-heading p, .panel-title p { margin: 0; color: var(--muted); font-size: 13px; }
.eyebrow { color: var(--primary-dark); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.primary-button, .secondary-button, .danger-button, .text-button { height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent; font-size: 13px; font-weight: 700; cursor: pointer; }
.primary-button { color: #fff; background: var(--primary); box-shadow: 0 8px 18px rgba(14,165,233,.16); }
.primary-button:hover { background: var(--primary-dark); }
.secondary-button { color: #41516a; background: #fff; border-color: var(--line); }
.danger-button { color: #fff; background: var(--red); }
.text-button { height: auto; color: var(--muted); padding: 0 5px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card { min-height: 130px; display: flex; align-items: center; gap: 15px; padding: 21px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric-card.accent { border-color: #cdeefa; }
.metric-card > div:last-child { display: grid; }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-card strong { margin: 5px 0 3px; font-size: 28px; line-height: 1; letter-spacing: -.7px; }
.metric-card small { color: #9ba6b6; font-size: 10px; }
.metric-icon { width: 46px; height: 46px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 13px; color: var(--primary-dark); background: var(--primary-soft); font-size: 20px; }
.metric-icon.orange { color: var(--orange); background: var(--orange-soft); }
.metric-icon.blue { color: #4a76df; background: #eaf0ff; }
.metric-icon.green { color: var(--green); background: var(--green-soft); }

.dashboard-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; margin-bottom: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-title { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; }
.panel-title h2 { margin: 0 0 4px; font-size: 15px; letter-spacing: -.2px; }
.panel-title > a { color: var(--primary-dark); font-size: 12px; font-weight: 700; }
.panel-chip { padding: 6px 9px; border-radius: 8px; color: #63728a; background: var(--surface-soft); font-size: 10px; font-weight: 700; }
.chart-box { position: relative; height: 270px; padding: 5px 18px 18px; }
.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 13px 16px; color: #7d899c; background: #f8fafc; text-align: left; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .045em; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid #edf0f4; color: #425067; vertical-align: middle; }
tbody tr:hover { background: #fbfdfe; }
td strong, td small { display: block; }
td strong { max-width: 250px; color: #253047; font-size: 12px; }
td small { margin-top: 3px; color: #929dad; font-size: 10px; }
.ticket-number { color: var(--primary-dark); font-weight: 800; }
.subject-cell { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.badge.open { color: #c66b14; background: var(--orange-soft); }
.badge.in_progress { color: #2d65d3; background: #eaf0ff; }
.badge.closed { color: #138153; background: var(--green-soft); }
.row-action { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: #7d8ca2; }
.row-action:hover { color: var(--primary-dark); background: var(--primary-soft); }
.empty-cell { padding: 44px !important; color: var(--muted); text-align: center; }
.empty-cell i, .empty-cell strong, .empty-cell span { display: block; }
.empty-cell i { margin-bottom: 9px; font-size: 28px; }
.empty-cell span { margin-top: 5px; font-size: 11px; }

.filter-bar { display: grid; grid-template-columns: minmax(220px, 1fr) 180px 220px auto auto; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.filter-bar select, .filter-search, .inline-action input, .stack-form input { height: 40px; border: 1px solid var(--line); border-radius: 10px; color: #425067; background: #fff; outline: none; }
.filter-bar select { padding: 0 12px; }
.filter-search { display: flex; align-items: center; gap: 9px; padding: 0 12px; }
.filter-search i { color: #91a0b5; }
.filter-search input { width: 100%; border: 0; outline: 0; }
.pagination { min-height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.pagination > div { display: flex; align-items: center; gap: 12px; }
.pagination a { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; }
.pagination a.disabled { opacity: .35; pointer-events: none; }

.back-link { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.title-row { display: flex; align-items: center; gap: 10px; }
.title-row h1 { margin-bottom: 4px; }
.detail-heading { align-items: center; }
.detail-heading > div:first-child { min-width: 0; }
.detail-heading p { max-width: 760px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-action { display: flex; gap: 8px; }
.inline-action input { width: 210px; padding: 0 12px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) 320px; gap: 18px; align-items: start; }
.conversation-panel {
    min-width: 0;
    height: calc(100vh - 244px);
    min-height: 480px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.timeline {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 8px 20px 22px;
    background: #fafcfd;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.timeline-item { width: min(78%, 650px); margin: 14px 0; }
.timeline-item.support, .timeline-item.web { margin-left: auto; }
.timeline-item.event { width: 100%; margin: 12px auto; text-align: center; }
.timeline-meta { display: flex; justify-content: space-between; gap: 12px; margin: 0 4px 5px; color: #8b97a9; font-size: 9px; }
.timeline-meta strong { color: #5b687c; }
.message-bubble { padding: 12px 14px; color: #344159; background: #fff; border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; line-height: 1.55; white-space: pre-wrap; font-size: 12px; }
.timeline-item.support .message-bubble, .timeline-item.web .message-bubble { color: #0c5578; background: #e7f7fd; border-color: #ccecf8; border-radius: 14px 4px 14px 14px; }
.timeline-item.event .timeline-meta { justify-content: center; }
.timeline-item.event .message-bubble { display: inline-block; padding: 6px 11px; color: #788599; background: #f0f3f6; border: 0; border-radius: 999px; font-size: 10px; }
.reply-box { flex: 0 0 auto; padding: 16px 20px 20px; background: var(--surface); }
.reply-box textarea { width: 100%; min-height: 100px; resize: vertical; padding: 13px; border: 1px solid var(--line); border-radius: 12px; outline: none; }
.reply-box textarea:focus,
.filter-bar select:focus,
.filter-search:focus-within,
.inline-action input:focus,
.stack-form input:focus {
    border-color: #86d4f4;
    box-shadow: 0 0 0 3px rgba(14,165,233,.08);
}
.reply-box > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.reply-box small { color: var(--muted); font-size: 10px; }
.ticket-info { position: sticky; top: 92px; }
.ticket-info dl { margin: 0; padding: 0 20px 20px; }
.ticket-info dl div { padding: 12px 0; border-top: 1px solid var(--line); }
.ticket-info dt { margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 600; }
.ticket-info dd { margin: 0; color: #344159; font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }

.branch-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; align-items: start; }
.branch-form-panel { position: sticky; top: 92px; }
.stack-form { display: grid; gap: 15px; padding: 0 20px 20px; }
.stack-form label { display: grid; gap: 7px; color: #4e5c71; font-size: 11px; font-weight: 700; }
.stack-form input { padding: 0 12px; }
.branch-list { padding: 0 16px 16px; }
.branch-row { display: grid; grid-template-columns: 40px minmax(220px, 1fr) 170px 90px 38px; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.branch-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--primary-dark); background: var(--primary-soft); border-radius: 10px; }
.branch-main { display: grid; gap: 4px; }
.branch-main strong { color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.branch-main input { width: 100%; padding: 0; border: 0; outline: 0; color: #26334a; background: transparent; font-size: 12px; font-weight: 600; }
.topic-state { display: flex; align-items: center; gap: 7px; color: #b37a36; font-size: 10px; font-weight: 600; }
.topic-state.ready { color: var(--green); }
.switch { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 34px; height: 20px; position: relative; border-radius: 999px; background: #d8dee7; transition: .2s; }
.switch span::after { content: ""; width: 14px; height: 14px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.16); transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch em { font-style: normal; }
.alert { max-width: 100%; display: flex; align-items: center; gap: 8px; margin: 0 0 16px; padding: 11px 13px; border-radius: 10px; font-size: 11px; }
.alert.success { color: #13734d; background: var(--green-soft); border: 1px solid #c8eedb; }
.alert.error { color: #b73743; background: var(--red-soft); border: 1px solid #f6ccd0; }

.auth-body { min-height: 100vh; padding: 28px; background: #eef2f5; }
.auth-shell { width: min(1420px, 100%); min-height: calc(100vh - 56px); margin: 0 auto; display: grid; grid-template-columns: 1.05fr 1fr; overflow: hidden; background: #fff; border-radius: 22px; box-shadow: 0 24px 70px rgba(15,27,48,.11); }
.auth-visual { position: relative; margin: 18px; overflow: hidden; border-radius: 17px; background: #061021; }
.auth-visual::after { content: ""; position: absolute; inset: 0; background: rgba(0, 7, 20, .16); pointer-events: none; }
.auth-visual img { width: 100%; height: 100%; position: absolute; inset: 0; object-fit: cover; }
.auth-visual-copy { width: min(520px, 80%); position: relative; z-index: 2; margin: 12vh 0 0 11%; color: white; }
.auth-visual-copy .brand-mark { width: 52px; height: 52px; font-size: 24px; }
.auth-visual-copy h1 { margin: 25px 0 14px; font-size: clamp(27px, 2.4vw, 42px); line-height: 1.15; letter-spacing: -1.2px; }
.auth-visual-copy p { margin: 0; color: rgba(255,255,255,.75); font-size: 14px; line-height: 1.65; }
.auth-form-panel { min-width: 0; display: flex; flex-direction: column; padding: 42px clamp(34px, 7vw, 100px) 28px; }
.auth-brand { padding: 0; }
.auth-form { width: min(480px, 100%); margin: auto; display: grid; gap: 18px; }
.auth-form h2 { margin: 7px 0 6px; font-size: 29px; letter-spacing: -.7px; }
.auth-form > div:first-child p { margin: 0; color: var(--muted); font-size: 12px; }
.auth-form label { display: grid; gap: 8px; color: #3e4b60; font-size: 11px; font-weight: 700; }
.input-wrap { height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid var(--line); border-radius: 12px; transition: border-color .18s ease, box-shadow .18s ease; }
.input-wrap:focus-within { border-color: #86d4f4; box-shadow: 0 0 0 3px rgba(14,165,233,.08); }
.input-wrap > i { color: #99a5b6; }
.input-wrap input { width: 100%; border: 0; outline: 0; background: transparent; box-shadow: none; }
.input-wrap input:focus { border: 0; outline: 0; box-shadow: none; }
.password-toggle { padding: 5px; border: 0; color: #8d9aad; background: transparent; cursor: pointer; }
.auth-submit { width: 100%; height: 48px; margin-top: 5px; }
.auth-form-panel footer { margin-top: auto; color: #a4adba; text-align: center; font-size: 10px; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { grid-template-columns: 1fr 160px 190px; }
    .filter-bar .secondary-button, .filter-bar .text-button { grid-row: 2; }
    .ticket-layout { grid-template-columns: minmax(0, 1fr); }
    .conversation-panel { height: auto; min-height: 0; }
    .timeline { max-height: 560px; min-height: 300px; flex: none; }
    .ticket-info { position: static; }
    .branch-layout { grid-template-columns: 1fr; }
    .branch-form-panel { position: static; }
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { width: 244px; position: fixed; left: -260px; transition: left .25s ease; box-shadow: 18px 0 42px rgba(20,35,58,.14); }
    .sidebar.open { left: 0; }
    .mobile-menu { display: inline-grid; }
    .topbar { padding: 0 16px; }
    .status-dot { display: none; }
    .page { padding: 22px 16px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .auth-body { padding: 0; }
    .auth-shell { min-height: 100vh; grid-template-columns: 1fr; border-radius: 0; }
    .auth-visual { min-height: 280px; margin: 12px; }
    .auth-visual-copy { margin-top: 60px; }
    .auth-visual-copy h1 { margin-top: 15px; font-size: 26px; }
    .auth-form-panel { min-height: 600px; padding: 28px 24px 20px; }
}

@media (max-width: 620px) {
    .global-search { display: none; }
    .page-heading, .detail-heading { align-items: stretch; flex-direction: column; }
    .metric-grid { grid-template-columns: 1fr; }
    .filter-bar { grid-template-columns: 1fr; }
    .filter-bar .secondary-button, .filter-bar .text-button { grid-row: auto; }
    .detail-actions, .inline-action { width: 100%; }
    .inline-action { flex-direction: column; }
    .inline-action input { width: 100%; }
    .inline-action button { width: 100%; }
    .timeline-item { width: 92%; }
    .reply-box > div { align-items: stretch; flex-direction: column; }
    .branch-row { grid-template-columns: 40px minmax(0, 1fr) 38px; }
    .topic-state, .switch { grid-column: 2; }
    .branch-row > .icon-button { grid-column: 3; grid-row: 1; }
    .auth-visual { min-height: 230px; }
    .auth-visual-copy { width: 82%; margin: 38px 0 0 9%; }
    .auth-visual-copy p { font-size: 12px; }
}
