:root {
  --ink: #172033;
  --muted: #667085;
  --line: #e3e8f2;
  --surface: #ffffff;
  --canvas: #f5f7fb;
  --brand: #3658d4;
  --brand-dark: #2747bb;
  --success: #087f5b;
  --warning: #b55b00;
  --danger: #b42318;
  --radius: 16px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
.container { width: min(1120px, calc(100% - 40px)); margin: 0 auto; }
.site-header, .admin-header { color: #fff; background: #15233e; box-shadow: 0 2px 12px rgb(23 32 51 / 12%); }
.admin-header { background: #242b46; }
.header-content { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 750; letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { color: #fff; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: #5e7aff; font-size: 12px; letter-spacing: 0; }
.main-nav { display: flex; align-items: center; gap: 5px; }
.main-nav > a, .logout-form button { display: inline-flex; align-items: center; min-height: 38px; padding: 0 13px; border: 0; border-radius: 8px; color: #cbd5eb; background: transparent; cursor: pointer; font-weight: 600; }
.main-nav > a:hover, .main-nav > a.active, .logout-form button:hover { color: #fff; background: rgb(255 255 255 / 12%); }
.logout-form { margin: 0; }
.page-content { padding: 44px 0 64px; }
.hero, .query-heading, .page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin: 8px 0 28px; }
.hero h1, .query-heading h1, .page-title h1 { margin: 7px 0 9px; font-size: clamp(28px, 4vw, 42px); line-height: 1.16; letter-spacing: -.045em; }
.hero p, .query-heading p, .page-title p { margin: 0; color: var(--muted); font-size: 16px; }
.eyebrow { color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.hero-badge { display: grid; gap: 4px; min-width: 225px; padding: 17px 20px; border: 1px solid #dae2ff; border-radius: var(--radius); color: #334476; background: #edf1ff; }
.hero-badge strong { color: #2e49b7; }
.hero-badge span, .field-tip, .muted { color: var(--muted); font-size: 13px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 6px 24px rgb(21 35 62 / 4%); }
.form-panel { padding: clamp(22px, 4vw, 40px); }
.ticket-form, .stack-form { display: grid; gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
label, fieldset { display: grid; gap: 8px; color: #35405a; font-size: 14px; font-weight: 700; }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 9px; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid #cfd8e8; border-radius: 9px; outline: none; color: var(--ink); background: #fff; font-weight: 450; transition: border-color .15s, box-shadow .15s; }
input[type="file"] { padding: 9px; background: #f9fbff; font-size: 13px; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: #647fea; box-shadow: 0 0 0 3px rgb(100 127 234 / 17%); }
.radio-row { display: flex; flex-wrap: wrap; gap: 20px; }
.radio-row label, .switch-row { display: flex; align-items: center; gap: 7px; font-weight: 500; }
input[type="radio"], input[type="checkbox"] { width: auto; accent-color: var(--brand); }
.category-note { min-height: 40px; padding: 11px 14px; border-left: 3px solid #8ea4ff; border-radius: 0 8px 8px 0; color: #41506e; background: #f1f4ff; font-size: 14px; }
.category-note p { margin: 0; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 3px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 19px; border: 1px solid var(--brand); border-radius: 9px; color: #fff; background: var(--brand); cursor: pointer; font-weight: 750; transition: background .15s, transform .15s; }
.button:hover { color: #fff; background: var(--brand-dark); transform: translateY(-1px); }
.button-quiet { color: #44527a; border-color: #cbd5ed; background: #fff; }
.button-quiet:hover { color: var(--brand); background: #f4f6ff; }
.button-block { width: 100%; }
.notice { margin: 0 0 22px; padding: 13px 16px; border: 1px solid; border-radius: 10px; font-size: 14px; }
.notice.success { color: #056846; border-color: #a8e4c9; background: #ecfdf4; }
.notice.error { color: var(--danger); border-color: #f8c8c3; background: #fff3f2; }
.lookup-panel { padding: 22px; }
.lookup-form { display: flex; align-items: end; gap: 13px; }
.lookup-form label { flex: 1; }
.local-tickets { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 16px; color: var(--muted); font-size: 13px; }
.local-tickets button { padding: 4px 8px; border: 1px solid #d8e0ee; border-radius: 6px; color: #465576; background: #f9fbff; cursor: pointer; font-size: 12px; }
.ticket-results { display: grid; gap: 18px; margin-top: 36px; }
.ticket-results > h2, .panel h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.ticket-results > h2 span { color: var(--muted); font-size: 14px; font-weight: 500; }
.ticket-card { overflow: hidden; }
.ticket-card-header { display: flex; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--line); background: #fbfcff; }
.ticket-card-header > div { display: grid; gap: 5px; }
.ticket-number { color: #263d9d; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 800; letter-spacing: .025em; }
time { color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; align-self: flex-start; padding: 5px 9px; border-radius: 20px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-pending { color: #a34c00; background: #fff2df; }
.status-awaiting_user { color: #2855a9; background: #e9f0ff; }
.status-completed { color: #087456; background: #e4f8ef; }
.ticket-info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 0; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.ticket-info div { min-width: 0; }
.ticket-info dt { margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.ticket-info dd { margin: 0; color: #27344f; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.ticket-card > h3, .ticket-card > .conversation, .reply-area, .closed-note { margin-left: 24px; margin-right: 24px; }
.ticket-card > h3 { margin-top: 22px; margin-bottom: 13px; font-size: 15px; }
.conversation { display: grid; gap: 12px; }
.message { max-width: min(85%, 700px); padding: 14px 16px; border-radius: 12px; }
.message-user { border: 1px solid #dfe5f1; background: #f6f8fc; }
.message-admin { justify-self: end; color: #fff; background: #3c5dd5; }
.message-meta { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 7px; font-size: 12px; }
.message-admin time { color: #d9e2ff; }
.message-content { overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.attachment { display: inline-flex; align-items: center; gap: 7px; max-width: 220px; padding: 6px 8px; border-radius: 7px; color: inherit; background: rgb(255 255 255 / 16%); font-size: 12px; overflow: hidden; }
.message-user .attachment { color: #344668; background: #e9eef8; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment img { display: block; width: 42px; height: 32px; border-radius: 4px; object-fit: cover; }
.reply-area { margin-top: 25px; padding: 20px 0; border-top: 1px solid var(--line); }
.reply-area h3 { margin: 0 0 12px; font-size: 16px; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.reply-actions input { max-width: 60%; }
.close-ticket-form { margin-top: 12px; }
.closed-note { margin-top: 20px; margin-bottom: 20px; color: #4e5c78; font-size: 14px; }
.empty-state { color: var(--muted); text-align: center; }
.site-footer { padding: 24px 0; border-top: 1px solid var(--line); color: var(--muted); background: #fff; font-size: 13px; }
.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 25px; background: radial-gradient(circle at top right, #e5ebff 0, transparent 34%), #f3f6fc; }
.auth-card { width: min(440px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: 0 22px 65px rgb(47 65 112 / 13%); }
.install-card { width: min(600px, 100%); }
.auth-card h1 { margin: 8px 0; font-size: 28px; letter-spacing: -.04em; }
.auth-card > .muted { margin: 0 0 25px; }
.back-link { display: inline-block; margin-top: 21px; color: #53617f; font-size: 14px; }
.admin-content { padding-top: 36px; }
.page-title { margin-top: 0; }
.filter-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.filter-tabs a { padding: 8px 13px; border-radius: 8px; color: #54627f; background: #eaf0f8; font-size: 14px; font-weight: 700; }
.filter-tabs a.active { color: #fff; background: var(--brand); }
.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 820px; border-collapse: collapse; font-size: 14px; }
th, td { padding: 15px 18px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: #66748f; background: #f9fbfe; font-size: 12px; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcff; }
.table-link { font-weight: 700; }
.empty-cell { color: var(--muted); text-align: center; }
.detail-title { margin-top: 17px; }
.details-panel, .conversation-panel, .reply-panel { padding: 24px; margin-top: 18px; }
.admin-ticket-info { padding: 0; border: 0; grid-template-columns: repeat(3, 1fr); }
.conversation-panel h2, .reply-panel h2 { margin-bottom: 18px; }
.reply-panel > .muted { margin-top: -10px; margin-bottom: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-card { padding: 24px; }
.settings-card h2 { margin-bottom: 15px; }
.settings-card > .muted { margin-top: -6px; margin-bottom: 16px; }
.inline-select { margin-bottom: 16px; }
.mail-settings { grid-column: 1 / -1; }
.test-mail-form { display: flex; align-items: end; gap: 12px; margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.test-mail-form label { flex: 1; }

@media (max-width: 720px) {
  .container { width: min(100% - 28px, 1120px); }
  .header-content { min-height: auto; align-items: flex-start; flex-direction: column; gap: 10px; padding: 15px 0; }
  .main-nav { width: 100%; justify-content: space-between; gap: 2px; }
  .main-nav > a, .logout-form button { padding: 0 8px; font-size: 13px; }
  .page-content { padding: 30px 0 42px; }
  .hero, .query-heading, .page-title { align-items: flex-start; flex-direction: column; gap: 18px; margin-bottom: 22px; }
  .hero h1, .query-heading h1, .page-title h1 { font-size: 31px; }
  .hero-badge { width: 100%; }
  .form-grid, .settings-grid { grid-template-columns: 1fr; gap: 16px; }
  .form-panel { padding: 20px; }
  .lookup-form, .test-mail-form { align-items: stretch; flex-direction: column; }
  .lookup-form .button, .test-mail-form .button { width: 100%; }
  .ticket-card-header { padding: 17px; }
  .ticket-info, .admin-ticket-info { grid-template-columns: repeat(2, 1fr); padding: 17px; gap: 14px; }
  .ticket-card > h3, .ticket-card > .conversation, .reply-area, .closed-note { margin-left: 17px; margin-right: 17px; }
  .message { max-width: 100%; }
  .reply-actions { align-items: stretch; flex-direction: column; }
  .reply-actions input { max-width: 100%; }
  .reply-actions .button { width: 100%; }
  .details-panel, .conversation-panel, .reply-panel, .settings-card { padding: 18px; }
  .mail-settings { grid-column: auto; }
}

@media (max-width: 420px) {
  .brand { font-size: 14px; }
  .ticket-info, .admin-ticket-info { grid-template-columns: 1fr; }
  .auth-card { padding: 25px; }
}
