:root {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  color: #243247;
  background: #f3f7fb;
  --label-column: clamp(260px, 23vw, 370px);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
.hidden { display: none !important; }
button, input, select { font: inherit; }
button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid #d1dfec;
  border-radius: 4px;
  background: #fff;
  color: #334155;
  cursor: pointer;
}
button:hover { background: #f0f5fc; }
button.primary { color: #fff; background: #2366c8; border-color: #2366c8; font-weight: 600; }
button.primary:hover { background: #1654b2; }
button:focus-visible, input:focus-visible, select:focus-visible, .table-scroll:focus-visible {
  outline: 3px solid #6aa2ef;
  outline-offset: 2px;
}

.topbar {
  min-height: 86px;
  padding: 8px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  background: #fff;
  border-bottom: 2px solid #d8e7fa;
}
.top-actions { flex: 1 1 590px; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.top-actions button { font-size: 14px; white-space: nowrap; }

.page-title {
  flex: 0 1 auto;
  min-width: 270px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.page-title-copy { min-width: 0; }
.page-title h1 { margin: 0; font-size: 20px; line-height: 1.2; white-space: nowrap; }
.page-logo { display: block; flex: none; width: 106px; height: 68px; object-fit: contain; }
.page-title span { display: block; margin-top: 5px; color: #64748b; font-size: 12px; line-height: 1.3; overflow-wrap: anywhere; }
.filters {
  min-height: 86px;
  margin: 14px 12px 12px;
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px 16px;
  background: #fff;
  border: 1px solid #d5e2f0;
  border-radius: 4px;
}
.filter-group { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.filter-group label { color: #63748b; font-size: 12px; font-weight: 700; letter-spacing: .25px; }
.filter-group input, .filter-group select { height: 42px; min-width: 180px; padding: 7px 10px; border: 1px solid #cbd9e8; border-radius: 4px; background: #fff; color: #243247; font-size: 14px; }
.filter-group select { min-width: 280px; }
.filter-apply { min-height: 42px; }
.filter-caption { margin: 0 0 10px auto; color: #728094; font-size: 13px; }
.notice, .error { margin: 10px 12px; padding: 11px 14px; border-radius: 4px; font-size: 14px; line-height: 1.4; }
.notice { background: #fff8e3; border: 1px solid #efdb9b; color: #785a17; }
.error { background: #fff0f0; border: 1px solid #e8b6b6; color: #9f3030; }
.period-label { margin: 14px 12px 18px; font-size: 14px; font-weight: 700; }

.cards { margin: 0 12px 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card, .table-card { min-width: 0; background: #fff; border: 1px solid #d4e0ec; border-radius: 4px; box-shadow: 0 5px 14px #d9e3ef4f; }
.card { min-height: 205px; }
.card h2 { min-height: 45px; margin: 0; padding: 12px 15px; border-bottom: 1px solid #d5e1ee; color: #667588; font-size: 16px; line-height: 1.25; }
.card-body { padding: 8px 15px; }
.card-body > div { min-height: 46px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 16px; border-bottom: 1px solid #e0e8f2; font-size: 14px; }
.card-body > div:last-child { border: 0; }
.card-body b { min-width: 0; overflow-wrap: anywhere; }
.card strong { color: #245fc6; font-size: 15px; text-align: right; white-space: nowrap; }
.chart-card { min-height: 245px; }
.chart-legend { min-height: 35px; padding: 6px 14px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: 13px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 12px; height: 12px; flex: none; border-radius: 2px; }
.chart-legend i.orange { background: #f2673a; }
.chart-legend i.blue { background: #2567c9; }
.chart { height: 152px; margin: 0 10px 8px; overflow-x: auto; overflow-y: hidden; }
.chart svg { display: block; width: 100%; min-width: 620px; height: 145px; }

.table-card { margin: 0 12px 32px; }
.table-head { min-height: 52px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid #e3ebf2; color: #5d6d81; font-size: 14px; font-weight: 700; }
.scroll-hint { display: none; }
.table-scroll { width: 100%; max-height: clamp(420px, 68vh, 760px); overflow: auto; scrollbar-color: #a9bdd5 #eff4fa; }
.table-card table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 14px; }
.table-card th, .table-card td {
  width: 116px;
  min-width: 116px;
  height: 38px;
  padding: 8px 10px;
  border-bottom: 1px solid #e6ecf3;
  color: #263241;
  line-height: 1.35;
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
}
.table-card th:first-child, .table-card td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--label-column);
  min-width: var(--label-column);
  max-width: var(--label-column);
  border-right: 1px solid #dce5f0;
  background: #fff;
  box-shadow: 2px 0 4px #cbd9e844;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}
.table-card thead th { position: sticky; top: 0; z-index: 3; background: #fff; color: #37465b; font-weight: 700; box-shadow: 0 2px 3px #cbd9e866; }
.table-card thead th:first-child { z-index: 5; box-shadow: 2px 2px 4px #cbd9e866; }
.table-card tbody .section-row td { background: #f1f5fa; font-weight: 700; }
.table-card tbody .section-row td:first-child { background: #f1f5fa; }
.table-card tbody .subtotal td { background: #fbfcfe; border-top: 1px solid #d6e3f0; font-weight: 700; }
.table-card tbody .subtotal td:first-child { background: #fbfcfe; }
.table-card tbody .spacer td { height: 18px; padding: 0; background: #fff; }
.table-card .positive { background: #eefaf3; color: #245c39; font-weight: 600; }
.table-card .negative, .table-card .loss { background: #fff0f2; color: #b52331; font-weight: 700; }
.table-card tfoot .result-row th, .table-card tfoot .result-row td { height: 48px; border-top: 2px solid #a9c9ee; background: #eaf3ff; color: #174f9f; font-weight: 800; }
.table-card tfoot .result-row th:first-child { z-index: 3; background: #eaf3ff; }
.table-card tfoot .result-row td.loss { background: #ffe9eb; color: #a91e2a; }
.table-card tfoot .result-total { border-left: 2px solid #a9c9ee; font-size: 15px; }
.table-summary { min-height: 64px; padding: 14px 18px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; border-top: 1px solid #c9d9ea; background: #f8fbff; color: #3c4d63; font-size: 17px; font-weight: 700; }
.table-summary strong { color: #205fbd; font-size: 20px; white-space: nowrap; }
.table-summary strong.loss { color: #b52331; }

.login-shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(430px, 1fr); background: #fbfaf7; }
.login-brand-panel { position: relative; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #a26a10; }
.login-hero-logo { display: block; width: min(100%, 940px); max-height: min(80vh, 820px); object-fit: contain; }
.login-content { min-width: 0; display: flex; align-items: center; justify-content: center; padding: 54px clamp(26px, 6vw, 96px); }
.login-content-inner { width: min(100%, 460px); }
.login-content h1 { margin: 0; color: #302a21; font-size: clamp(32px, 3vw, 46px); line-height: 1.15; letter-spacing: -.04em; overflow-wrap: anywhere; }
.login-card { margin-top: clamp(28px, 6vh, 64px); padding-top: 28px; border-top: 1px solid #e3d9c9; }
.login-card h2 { margin: 0 0 24px; color: #302a21; font-size: 20px; }
.login-card label, dialog label { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; font-size: 14px; font-weight: 600; }
.login-card label { color: #544c41; }
.login-card input, dialog input { min-width: 0; min-height: 42px; padding: 8px; border: 1px solid #cdd8e5; border-radius: 4px; }
.login-card input { min-height: 50px; padding: 10px 13px; border-color: #d7cdbd; background: #fff; color: #302a21; }
.login-card input:focus-visible, .login-card button:focus-visible { outline-color: #a26a10; }
.login-card button { width: 100%; min-height: 50px; margin-top: 8px; }
.login-card button.primary { background: #a26a10; border-color: #a26a10; }
.login-card button.primary:hover { background: #88570b; border-color: #88570b; }
.form-message { min-height: 18px; color: #b53232; font-size: 13px; }
dialog { width: min(440px, 95vw); max-height: 90vh; padding: 24px; border: 1px solid #cfdaea; border-radius: 5px; box-shadow: 0 20px 60px #1f345566; }
dialog::backdrop { background: #15294388; }
dialog h2 { margin: 0 0 22px; font-size: 20px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 15px; }
.admin-dialog { width: min(680px, 95vw); }
.dialog-content { max-height: calc(90vh - 50px); overflow: auto; }
dialog h3 { margin-top: 24px; padding-bottom: 8px; border-bottom: 1px solid #d9e3ed; font-size: 16px; }
.admin-dialog #token-form { display: flex; align-items: end; gap: 9px; }
.admin-dialog #token-form label { flex: 1; margin: 0; }
.hint { color: #728094; font-size: 13px; line-height: 1.4; }
.user-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 7px; border-bottom: 1px solid #e7edf4; }
.user-row small { color: #728094; }
.user-row button { color: #a92c36; }
.user-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.user-form input { flex: 1 1 175px; }
.user-form button { white-space: nowrap; }

@media (max-width: 1800px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-card { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  :root { --label-column: 250px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .chart-card { grid-column: auto; }
  .top-actions { flex-basis: 390px; }
  .filter-caption { display: none; }
  .login-shell { grid-template-columns: minmax(0, 1fr); }
  .login-brand-panel { height: clamp(210px, 30vh, 310px); }
  .login-hero-logo { width: min(75%, 430px); max-height: calc(100% - 18px); }
  .login-content { padding: 42px 28px 55px; }
  .login-content-inner { width: min(100%, 500px); }
  .login-content h1 { font-size: clamp(32px, 6vw, 46px); }
}

@media (min-width: 701px) and (max-width: 800px) {
  .top-actions { flex-basis: 355px; }
  .top-actions button { padding-left: 10px; padding-right: 10px; font-size: 13px; }
}

@media (max-width: 700px) {
  .page-title, .top-actions { flex-basis: 100%; }
  .top-actions { justify-content: flex-start; }
}

@media (max-width: 640px) {
  :root { --label-column: clamp(170px, 48vw, 230px); }
  .topbar { padding: 12px; }
  .top-actions { width: 100%; }
  .top-actions button { flex: 1 1 calc(50% - 8px); min-width: 0; white-space: normal; }
  .page-title { min-width: 0; }
  .page-title h1 { font-size: 18px; }
  .page-logo { width: 98px; height: 68px; }
  .filters { padding: 12px; }
  .filter-group, .filter-group input, .filter-group select, .filter-apply { width: 100%; min-width: 0; }
  .cards { margin-left: 10px; margin-right: 10px; }
  .card { min-height: 0; }
  .card-body > div { min-height: 48px; }
  .table-card { margin-left: 10px; margin-right: 10px; }
  .table-card th, .table-card td { width: 126px; min-width: 126px; padding: 8px; }
  .scroll-hint { display: block; margin: 0; padding: 8px 12px; color: #607590; background: #f7faff; font-size: 13px; }
  .admin-dialog #token-form { align-items: stretch; flex-direction: column; }
  .login-content { padding: 32px 22px 44px; }
}

@media (max-width: 380px) {
  .card-body > div { grid-template-columns: 1fr; gap: 2px; padding: 8px 0; }
  .card strong { text-align: left; }
  .table-summary strong { font-size: 18px; }
  dialog { padding: 16px; }
}
