:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --ink: #17232a;
  --muted: #65747d;
  --line: #d6dee3;
  --dark: #13252d;
  --accent: #0f7891;
  --accent-dark: #0b6176;
  --danger: #b93232;
  --ok: #137a41;
  --warn: #c78700;
  --shadow: 0 8px 24px rgba(18, 35, 42, .08);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; color: var(--ink); background: var(--bg); font-size: 13px; }
button, input, select, textarea { font: inherit; }
button { border: 0; border-radius: 5px; padding: 7px 10px; cursor: pointer; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 32px; border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; background: white; }
textarea { resize: vertical; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
h1, h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 22px; }
h3 { margin-bottom: 8px; font-size: 16px; }
.hidden { display: none !important; }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; margin-bottom: 2px; }
.primary { background: var(--accent); color: white; }
.primary:hover { background: var(--accent-dark); }
.secondary { background: #e8eef2; color: var(--ink); }
.danger { color: var(--danger); }
.small { padding: 5px 8px; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 22px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card h1 { font-size: 34px; margin-bottom: 8px; }
.message { color: var(--danger); min-height: 18px; margin: 0; }

.app { display: grid; grid-template-columns: 176px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--dark); color: white; padding: 14px 10px; display: grid; align-content: start; gap: 8px; }
.brand { display: flex; align-items: center; gap: 9px; margin: 0 4px 12px; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; background: white; color: var(--dark); border-radius: 50%; font-size: 20px; font-weight: 900; }
.brand small { display: block; color: #b9c8ce; }
.nav { width: 100%; text-align: left; background: transparent; color: #dce7eb; padding: 8px 9px; }
.nav.active, .nav:hover { background: rgba(255,255,255,.12); color: white; }

.workspace { padding: 12px; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; }
.quick-strip { display: flex; gap: 7px; }
.quick { min-width: 58px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--ink); }
.quick strong { color: var(--accent); }
.price-status { align-self: center; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; white-space: nowrap; box-shadow: var(--shadow); }
.buying-power-status { color: var(--ink); font-weight: 700; }
.mobile-label { display: none; }

.overview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.overview-card { min-height: 118px; display: grid; place-items: center; align-content: center; gap: 8px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow); }
.overview-card span { color: var(--muted); font-weight: 700; }
.overview-card strong { color: var(--accent); font-size: 36px; }
.overview-card-events strong { color: var(--danger); }
.overview-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.overview-panel { display: grid; gap: 6px; }
.overview-panel strong { font-size: 17px; }
.overview-panel small { color: var(--muted); }
.overview-process { width: 100%; min-height: 48px; font-size: 16px; }
.overview-process:disabled { opacity: .55; cursor: default; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 10px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.stock-list { margin-top: 8px; }
.stock-table { table-layout: fixed; }
.stock-table th:first-child, .stock-table td:first-child { width: 32%; }
.stock-table th:not(:first-child), .stock-table td:not(:first-child) { text-align: right; }
.stock-row { cursor: pointer; }
.stock-row:hover, .stock-row:focus { background: #f3f7f9; outline: none; }
.stock-row:focus { box-shadow: inset 3px 0 var(--accent); }

.detail-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 8px; }
.stock-title { font-size: 22px; margin: 0; }
.badge { display: inline-flex; align-items: center; min-height: 20px; padding: 2px 7px; border-radius: 999px; background: #edf1f4; color: var(--muted); font-weight: 700; font-size: 11px; }
.badge.ok { background: #dff4e8; color: var(--ok); }
.badge.warn { background: #fff1ce; color: var(--warn); }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(90px, 1fr)); gap: 7px; margin-bottom: 10px; }
.metric { background: #f7fafb; border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { font-size: 17px; }

.pot-list { border: 1px solid var(--line); border-radius: 6px; }
.pot-table { min-width: 850px; }
.pot-table th:not(:first-child), .pot-table td:not(:first-child) { text-align: right; }
.pot-table .check-column { width: 52px; text-align: center; }
.pot-table input[type="checkbox"] { width: 16px; min-height: 16px; margin: 0; cursor: not-allowed; }
.pot-table .insurance-column { width: 82px; }
.pot-table .insurance-input { width: 68px; min-height: 27px; padding: 3px 5px; text-align: right; }
.pot-row:last-child td { border-bottom: 0; }
.pot-row.pot-free { color: var(--muted); }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 7px 6px; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; background: #f7fafb; }
.event-work-card { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(420px, 1.6fr); gap: 12px; border: 1px solid #b8dec9; background: #f0fbf5; border-radius: 7px; padding: 10px; margin-bottom: 10px; }
.event-work-card h3 { margin-bottom: 4px; }
.event-work-card p { margin-bottom: 4px; }
.event-work-card small { display: block; color: var(--muted); }
.event-approve-form { display: grid; grid-template-columns: 1.1fr 1.4fr .8fr .8fr .8fr auto; gap: 7px; align-items: end; }
.event-approve-form label { min-width: 0; }
.admin-grid { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.row-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.excel-import-panel { margin-bottom: 10px; }
.outlook-panel { margin-bottom: 10px; }
.outlook-code { display: inline-block; font-size: 20px; letter-spacing: .08em; padding: 6px 10px; margin: 5px 0; background: #f7fafb; border: 1px solid var(--line); border-radius: 5px; }
.excel-preview-grid { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 7px; margin: 10px 0; }
.excel-preview-item { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: #f7fafb; }
.excel-preview-item span { display: block; color: var(--muted); font-size: 11px; }
.excel-name-list { color: var(--muted); margin-bottom: 8px; }

dialog { border: 0; border-radius: 8px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.24); width: min(720px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(19, 37, 45, .48); }
.stock-detail-dialog { width: min(1050px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
.stock-detail-shell { padding: 12px; overflow: auto; max-height: calc(100vh - 24px); }
.stock-detail-actions { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.dialog-form { padding: 14px; display: grid; gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; right: 14px; bottom: 14px; background: var(--dark); color: white; padding: 10px 12px; border-radius: 6px; opacity: 0; transform: translateY(12px); transition: .18s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }

.cash-mode-panel { margin-bottom: 10px; }
.cash-toggle { display: flex; gap: 8px; }
.cash-toggle button { min-width: 76px; }
.cash-toggle button.active { background: var(--dark); color: white; box-shadow: inset 0 -3px rgba(0,0,0,.22); }
.buy-queue-list { display: flex; flex-wrap: wrap; gap: 6px; }
.buy-queue-list span { background: #fff1ce; color: #755000; border-radius: 999px; padding: 5px 9px; font-weight: 700; }
.compact-event-list { display: grid; gap: 7px; margin-top: 12px; }
.compact-event-list div { display: flex; justify-content: space-between; gap: 12px; padding: 9px; border: 1px solid var(--line); border-radius: 7px; background: #f7fafb; }
.compact-event-list span { color: var(--muted); }

.workflow-dialog { width: min(520px, calc(100vw - 20px)); max-height: calc(100vh - 20px); border-radius: 18px; overflow: visible; }
.workflow-dialog::backdrop { background: rgba(8, 20, 26, .72); }
.workflow-shell { position: relative; min-height: 520px; padding: 30px 22px 22px; text-align: center; display: grid; align-content: center; }
.workflow-close { position: absolute; top: 8px; right: 10px; width: 44px; height: 44px; border-radius: 50%; background: transparent; color: var(--muted); font-size: 30px; line-height: 1; }
.workflow-counter { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; margin-bottom: 18px; }
.workflow-type { display: inline-flex; justify-self: center; border-radius: 999px; padding: 7px 15px; color: white; font-weight: 900; letter-spacing: .08em; margin-bottom: 18px; }
.workflow-type-buy { background: #166aa5; }
.workflow-type-sell { background: #bd3434; }
.workflow-type-cancel, .workflow-type-unmatched { background: #6a7075; }
.workflow-shell h2 { font-size: clamp(28px, 8vw, 42px); margin-bottom: 12px; }
.workflow-quantity { font-size: clamp(25px, 7vw, 36px); font-weight: 900; margin-bottom: 7px; }
.workflow-partial { color: var(--muted); font-size: 17px; font-weight: 800; margin-bottom: 22px; }
.workflow-actions { display: grid; gap: 16px; }
.workflow-button { width: 100%; min-height: 88px; border-radius: 15px; color: white; padding: 14px 18px 18px; transform: translateY(0); transition: transform .08s, box-shadow .08s, filter .08s; }
.workflow-button strong, .workflow-button span { display: block; }
.workflow-button strong { font-size: 21px; letter-spacing: .03em; }
.workflow-button span { margin-top: 6px; font-size: 18px; }
.workflow-button:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.28); }
.workflow-buy { background: linear-gradient(#2386c8, #116295); box-shadow: 0 8px 0 #0b456b, 0 13px 24px rgba(17,98,149,.25); }
.workflow-sell { background: linear-gradient(#df5555, #b52c2c); box-shadow: 0 8px 0 #7b2020, 0 13px 24px rgba(181,44,44,.25); }
.workflow-sell.opened { background: linear-gradient(#f3a0a0, #dc7777); box-shadow: 0 8px 0 #a75050, 0 13px 24px rgba(181,44,44,.18); }
.workflow-buy.opened { background: linear-gradient(#89c6ed, #5da9d8); box-shadow: 0 8px 0 #397fa9, 0 13px 24px rgba(17,98,149,.18); }
.workflow-ok { background: linear-gradient(#35a867, #18804a); box-shadow: 0 8px 0 #0d5932, 0 13px 24px rgba(24,128,74,.25); }
.workflow-queue { display: grid; gap: 5px; margin: 0 0 18px; padding: 13px; background: #fff1ce; color: #755000; border: 1px solid #efcd76; border-radius: 10px; }
.workflow-later { margin-top: 25px; background: transparent; color: var(--muted); text-decoration: underline; }
.workflow-icon { font-size: 70px; color: var(--ok); margin-bottom: 10px; }
.workflow-done h2 { font-size: 34px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; overflow-x: auto; }
  .brand { min-width: 120px; }
  .admin-grid, .event-work-card, .event-approve-form { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .excel-preview-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .stock-detail-dialog { width: 100vw; max-width: none; height: 100vh; max-height: none; border-radius: 0; }
  .stock-detail-shell { max-height: 100vh; }
  .stock-table { min-width: 620px; }
  .workflow-dialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; border-radius: 0; margin: 0; }
  .workflow-shell { min-height: 100dvh; padding: 48px 18px 24px; }
  .compact-event-list div { display: grid; }
  .workspace { padding: 8px; }
  .topbar { display: block; padding-bottom: 8px; }
  .topbar > div:first-child { display: none; }
  .quick-strip { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 38px repeat(3, 42px); gap: 4px; }
  .price-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; padding: 5px 6px; font-size: 11px; }
  .quick { min-width: 0; width: 100%; min-height: 38px; padding: 3px; }
  .quick strong { font-size: 14px; }
  .desktop-label { display: none; }
  .mobile-label { display: inline; font-size: 20px; line-height: 1; }
  .overview-grid { gap: 6px; }
  .overview-card { min-height: 92px; padding: 8px 3px; }
  .overview-card span { font-size: 11px; }
  .overview-card strong { font-size: 29px; }
  .overview-details { grid-template-columns: 1fr; gap: 6px; }
}
