:root {
  color-scheme: dark;
  --canvas: #101313;
  --panel: #171b1a;
  --panel-raised: #1d2220;
  --line: #2b3230;
  --line-soft: #222826;
  --text: #e8ece8;
  --muted: #8c9790;
  --subtle: #65716a;
  --accent: #b8ed79;
  --accent-dark: #18230e;
  --danger: #ff8c82;
  --mono: 'Cascadia Code', Consolas, monospace;
  --sans: 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 340px; background: var(--canvas); color: var(--text); font: 14px/1.5 var(--sans); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
.app-frame { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { min-height: 70px; display: flex; align-items: center; gap: 46px; padding: 0 5.2vw; border-bottom: 1px solid var(--line-soft); background: #121615; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); font-size: 16px; font-weight: 500; letter-spacing: -.03em; text-decoration: none; }
.brand b { color: var(--accent); font-weight: 600; }
.brand-mark { width: 29px; height: 29px; border-radius: 8px; display: grid; place-items: center; color: #10150d; background: var(--accent); font-weight: 700; font-size: 15px; }
.main-nav { height: 70px; display: flex; align-items: stretch; gap: 28px; }
.nav-link { position: relative; border: 0; background: transparent; color: var(--muted); padding: 0 2px; cursor: pointer; }
.nav-link:hover, .nav-link.active { color: var(--text); }
.nav-link.active::after { position: absolute; content: ''; bottom: 0; left: 0; right: 0; height: 2px; background: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 20px; }
.current-user { max-width: 170px; overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.logout-button { border: 0; padding: 4px 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; }
.logout-button:hover { color: var(--accent); }
.local-indicator { display: flex; align-items: center; gap: 8px; color: var(--muted); font: 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.local-indicator i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px #b8ed7966; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; color: var(--muted); font-size: 19px; }
.icon-button:hover { color: var(--accent); border-color: #50663a; }
.main-content { width: min(1280px, calc(100% - 10.4vw)); flex: 1; margin: 0 auto; padding: 45px 0 68px; }
.app-footer { min-height: 48px; padding: 0 5.2vw; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line-soft); color: var(--subtle); font-size: 11px; }
.footer-separator { margin: 0 8px; color: #49534d; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 29px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font: 10px var(--mono); letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(25px, 3vw, 34px); line-height: 1.15; letter-spacing: -.045em; font-weight: 600; }
.subtitle { margin: 0; color: var(--muted); }
h2 { font-size: 17px; letter-spacing: -.02em; }
h3 { font-size: 13px; font-weight: 600; }
.button { min-height: 37px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 7px; padding: 0 13px; background: var(--panel-raised); color: var(--text); text-decoration: none; cursor: pointer; font-size: 12px; font-weight: 600; }
.button:hover { border-color: #536148; background: #232a25; }
.button.primary { color: #16200d; background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: #caef9c; }
.button.danger { color: var(--danger); }
.button.small { min-height: 30px; padding: 0 9px; font-size: 11px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.notice { margin-bottom: 20px; padding: 11px 14px; border: 1px solid #47603c; border-radius: 7px; color: #d0eab4; background: #1c2817; }
.notice.error { border-color: #71413c; color: #ffc2bb; background: #2a1b19; }
.table-wrap, .card { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); overflow: hidden; }
.inbox-toolbar { min-height: 51px; display: flex; align-items: center; justify-content: space-between; padding: 0 17px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.count-label { color: var(--text); font: 11px var(--mono); }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { height: 42px; padding: 0 15px; color: var(--subtle); background: #191e1c; font: 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
td { height: 62px; padding: 10px 15px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 12px; vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #1d2420; }
td strong { display: block; color: var(--text); font-size: 12px; font-weight: 500; }
td .secondary { display: block; max-width: 260px; margin-top: 3px; color: var(--subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 11px; }
.empty-state { padding: 65px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 49px; height: 49px; display: grid; place-items: center; margin: 0 auto 17px; border: 1px solid var(--line); border-radius: 14px; color: var(--accent); font: 23px var(--mono); background: #1b211e; }
.empty-state h2 { margin-bottom: 7px; color: var(--text); }
.empty-state p { margin-bottom: 20px; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 25px; margin-bottom: 24px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs { display: flex; gap: 5px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab { flex: 0 0 auto; padding: 11px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.card { padding: 20px; margin-bottom: 16px; }
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 17px; }
.card-title h2, .card-title h3 { margin: 0; }
.data-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 19px 25px; }
.data-item label { display: block; margin-bottom: 5px; color: var(--subtle); font: 10px var(--mono); text-transform: uppercase; letter-spacing: .06em; }
.data-item div { color: var(--text); overflow-wrap: anywhere; }
.json-block, .raw-block, .body-block { max-height: 560px; margin: 0; padding: 16px; overflow: auto; border: 1px solid var(--line-soft); border-radius: 7px; background: #101413; color: #ced8d0; font: 11px/1.65 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.raw-block { min-height: 300px; white-space: pre; }
.header-table td { height: auto; vertical-align: top; }
.header-table td:first-child { width: 25%; color: var(--accent); font-family: var(--mono); }
.preview-frame { width: 100%; min-height: 270px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.content-stack { display: grid; gap: 16px; }
.tree-list, .tree-list ul { margin: 0; padding-left: 22px; list-style: none; }
.tree-list { padding-left: 0; }
.tree-list li { position: relative; padding: 8px 0 8px 20px; color: var(--text); }
.tree-list li::before { position: absolute; left: 0; color: var(--accent); content: '↳'; }
.pill { display: inline-flex; align-items: center; padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font: 10px var(--mono); }
.scenario-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 20px; align-items: start; }
.scenario-list { display: grid; gap: 4px; }
.scenario-option { width: 100%; padding: 12px; text-align: left; border: 1px solid transparent; border-radius: 7px; background: transparent; cursor: pointer; }
.scenario-option:hover, .scenario-option.active { border-color: #3c4c32; background: #20291c; }
.scenario-option strong { display: block; color: var(--text); font: 11px var(--mono); }
.scenario-option span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: 11px; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid var(--line); border-radius: 6px; outline: none; padding: 9px 10px; color: var(--text); background: #111614; font-size: 12px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: #779f50; }
.field textarea { min-height: 110px; resize: vertical; font-family: var(--mono); }
.form-actions { display: flex; gap: 9px; margin-top: 15px; }
.scenario-description { color: var(--muted); font-size: 12px; }
.mobile-scroll { overflow-x: auto; }
.compose-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 2px 0 16px; }
.mode-switch, .compose-actions { display: flex; align-items: center; gap: 7px; }
.mode-switch { padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #141918; }
.mode-button { min-height: 31px; padding: 0 13px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; }
.mode-button.active { color: var(--accent); background: #27311f; }
.compose-grid { display: grid; gap: 15px; }
.compose-card { overflow: visible; }
.compose-card .card-title { align-items: flex-start; }
.compose-card .card-title h2 { margin-bottom: 5px; }
.compose-card .card-title p { margin-bottom: 0; }
.compose-card .form-grid { margin-top: 4px; }
.compose-card input[type='checkbox'] { width: 17px; height: 17px; accent-color: var(--accent); }
.header-tools { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.header-tools .field { min-width: 220px; }
.header-rows { display: grid; gap: 7px; }
.header-row { display: grid; grid-template-columns: minmax(140px, .75fr) minmax(220px, 2fr) auto; gap: 7px; align-items: center; }
.header-value-cell { display: grid; gap: 6px; min-width: 0; }
.header-date-controls { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(150px, .8fr); gap: 7px; }
.header-date-controls[hidden], .header-action[hidden] { display: none; }
.header-date-controls .field { min-width: 0; }
.header-date-controls .field label { font-size: 10px; }
.header-date-controls input, .header-date-controls select { width: 100%; min-height: 36px; border: 1px solid var(--line); border-radius: 6px; outline: none; padding: 8px 10px; color: var(--text); background: #111614; font: 11px var(--mono); }
.header-date-controls input:focus, .header-date-controls select:focus { border-color: #779f50; }
.header-action { justify-self: start; min-height: 30px; padding: 5px 9px; font-size: 11px; }
.header-row[data-generated-by-dkim='true'] { border-left: 2px solid var(--accent); padding-left: 6px; }
.header-row[data-generated-by-arc='true'] { border-left: 2px solid #83aaf2; padding-left: 6px; }
.header-row input, .header-row textarea { width: 100%; min-height: 36px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; outline: none; color: var(--text); background: #111614; font: 11px var(--mono); }
.header-row textarea { resize: vertical; }
.row-controls { display: flex; align-items: center; gap: 4px; }
.row-button { width: 29px; height: 29px; min-width: 29px; padding: 0; font-size: 13px; }
.attachment-list { display: grid; gap: 10px; margin-top: 14px; }
.attachment-row { padding: 13px; border: 1px solid var(--line-soft); border-radius: 7px; background: #141917; }
.attachment-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 11px; }
.attachment-heading strong { overflow: hidden; color: var(--text); font: 11px var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.attachment-row .form-grid { gap: 10px; }
.preview-wrap { display: grid; gap: 7px; margin-top: 17px; }
.preview-label { color: var(--muted); font-size: 11px; }
.compose-preview { min-height: 190px; }
.raw-editor { min-height: 500px !important; white-space: pre; }
.compose-actions .button { white-space: nowrap; }
body.is-compose-sending { overflow: hidden; }
.loading-overlay { position: fixed; z-index: 1000; inset: 0; display: grid; place-items: center; padding: 24px; background: rgb(7 10 9 / 76%); backdrop-filter: blur(3px); }
.loading-overlay[hidden] { display: none; }
.loading-dialog { width: min(360px, 100%); display: grid; justify-items: center; gap: 12px; padding: 28px; border: 1px solid #43513b; border-radius: 12px; background: var(--panel); box-shadow: 0 20px 70px #0009; text-align: center; }
.loading-dialog h2 { margin: 0; }
.loading-dialog p { margin: 0; color: var(--muted); font-size: 12px; }
.loading-spinner { width: 38px; height: 38px; border: 3px solid #364035; border-top-color: var(--accent); border-radius: 50%; animation: compose-loading-spin .8s linear infinite; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: 0 24px 80px #0005; }
.login-brand { margin-bottom: 34px; }
.login-card h1 { margin-bottom: 8px; }
.login-card .subtitle { margin-bottom: 28px; }
#login-form { display: grid; gap: 9px; }
#login-form label { margin-top: 7px; color: var(--muted); font-size: 12px; }
#login-form input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 7px; outline: none; padding: 9px 11px; color: var(--text); background: #111614; }
#login-form input:focus { border-color: #779f50; }
.login-error { margin: 5px 0 0; color: var(--danger); font-size: 12px; }
.login-submit { width: 100%; min-height: 42px; margin-top: 12px; }
@keyframes compose-loading-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none; } }
@media (max-width: 850px) {
  .topbar { gap: 25px; padding: 0 22px; }
  .main-content { width: calc(100% - 44px); padding-top: 32px; }
  .app-footer { padding: 0 22px; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 900px; }
  .scenario-layout { grid-template-columns: 1fr; }
  .scenario-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-row { grid-template-columns: minmax(100px, .7fr) minmax(160px, 2fr) auto; }
}
@media (max-width: 560px) {
  .topbar { min-height: 62px; gap: 16px; padding: 0 16px; }
  .topbar-right { gap: 9px; }
  .current-user { max-width: 72px; font-size: 10px; }
  .logout-button { font-size: 10px; }
  .main-nav { height: 62px; gap: 14px; }
  .nav-link { font-size: 11px; }
  .local-indicator { display: none; }
  .main-content { width: calc(100% - 32px); padding: 27px 0 45px; }
  .page-heading, .detail-header { align-items: flex-start; flex-direction: column; }
  .data-grid, .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .scenario-list { grid-template-columns: 1fr; }
  .compose-toolbar { align-items: flex-start; flex-direction: column; }
  .compose-actions { flex-wrap: wrap; }
  .header-tools { align-items: stretch; flex-direction: column; }
  .header-tools .field { min-width: 0; }
  .header-row { grid-template-columns: 1fr; padding: 10px; border: 1px solid var(--line-soft); border-radius: 7px; }
  .header-date-controls { grid-template-columns: 1fr; }
  .header-row .row-controls { justify-content: flex-end; }
  .app-footer { padding: 0 16px; }
  .app-footer span:last-child { display: none; }
  .login-card { padding: 25px; }
}
