:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1c2420;
  --muted: #627069;
  --line: #d8ded7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --amber: #b45309;
  --red: #b91c1c;
  --blue: #2563eb;
  --shadow: 0 14px 32px rgba(28, 36, 32, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 10px;
}

.summary div {
  min-width: 72px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: right;
}

.summary span {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.summary small {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 94px);
}

.controls {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: calc(100vh - 94px);
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #eef3ef;
}

.search,
.control-group {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.search span,
.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #cbd5cf;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

select[multiple] {
  min-height: 156px;
}

select[multiple] option {
  padding: 7px 9px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.segmented button,
.ghost {
  min-height: 40px;
  border: 1px solid #cbd5cf;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.segmented button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ghost {
  padding: 9px 14px;
}

.ghost:hover,
.segmented button:hover,
.icon-button:hover {
  border-color: var(--accent);
}

.content {
  padding: 22px clamp(18px, 3vw, 38px) 42px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.section-head h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

.section-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.card .chart-frame {
  aspect-ratio: 16 / 9;
}

.card button {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.chart-frame {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 10;
  border: 1px solid #cfd8d1;
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.13) 1px, transparent 1px),
    linear-gradient(rgba(15, 118, 110, 0.13) 1px, transparent 1px),
    #f9fbf8;
  background-size: 38px 38px;
}

.chart-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.placeholder {
  display: grid;
  gap: 8px;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.placeholder strong {
  color: var(--ink);
  font-size: 24px;
}

.card-caption {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.card-title-line {
  display: flex;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 550;
  line-height: 1.25;
  text-transform: uppercase;
  white-space: nowrap;
}

.card-title-line strong,
.card-title-line span,
.card-title-line time {
  min-width: 0;
}

.card-title-line strong {
  flex: 0 0 auto;
  font-weight: 850;
}

.card-title-line span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-title-line time {
  flex: 0 0 auto;
}

.card-caption p {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-category-line {
  display: flex;
  gap: 8px;
  align-items: center;
}

.action-rating {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  max-width: max-content;
  padding: 2px 8px 2px 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.25;
  text-transform: uppercase;
}

.action-dot {
  display: inline-block;
  width: 16px;
  height: 9px;
  border-radius: 999px;
  background: currentColor;
}

.action-actionable {
  color: #15803d;
  background: #ecfdf3;
}

.action-accumulate {
  color: #7c3aed;
  background: #f5f3ff;
}

.action-watch {
  color: #b45309;
  background: #fffbeb;
}

.action-hold {
  color: #2563eb;
  background: #eff6ff;
}

.action-trim {
  color: #b91c1c;
  background: #fef2f2;
}

.notes {
  margin-bottom: 0;
  color: #34413b;
  font-size: 14px;
  line-height: 1.45;
}

dialog {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.dialog-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  gap: 8px;
  align-items: center;
}

.close {
  z-index: 1;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.detail {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(640px, 1fr);
  gap: 18px;
  align-items: stretch;
  justify-content: start;
  height: 100vh;
  padding: 64px 18px 18px 0;
  background: #111815;
  overflow: auto;
}

.detail .large {
  justify-self: start;
  width: fit-content;
  height: calc(100vh - 82px);
  min-height: 0;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  background: #111815;
}

.detail .large img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: calc(100vh - 82px);
  object-fit: contain;
  background: #fff;
}

.analysis-card {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  width: 100%;
  height: calc(100vh - 82px);
  min-height: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.analysis-card section {
  padding-top: 12px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.analysis-header h2 {
  margin-bottom: 6px;
  font-size: 20px;
  line-height: 1.15;
}

.analysis-action {
  margin-bottom: 10px;
}

.analysis-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.analysis-card h3 {
  margin-bottom: 6px;
  color: #334155;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.analysis-card p {
  margin: 0;
  color: #0f172a;
  font-size: 13px;
  line-height: 1.45;
}

.admin-dialog {
  width: min(520px, calc(100vw - 32px));
  max-width: 520px;
  height: auto;
  max-height: calc(100vh - 32px);
  margin: auto;
  border-radius: 8px;
  background: transparent;
}

.admin-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.admin-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.admin-dialog.dragging {
  cursor: move;
}

.admin-head h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.admin-auth,
.admin-controls {
  display: grid;
  gap: 12px;
}

.admin-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.admin-check input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.admin-auth {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.admin-auth .label {
  grid-column: 1 / -1;
}

.admin-actions {
  display: flex;
  gap: 8px;
}

.admin-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.analysis-kv {
  display: grid;
  gap: 10px;
}

.analysis-kv div,
.rr-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f8fafc;
}

.analysis-kv span,
.rr-row span {
  color: #64748b;
  font-size: 13px;
}

.analysis-kv strong,
.rr-row strong {
  color: #0f172a;
  font-size: 13px;
  text-align: right;
}

.rr-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 1700px) {
  .detail {
    grid-template-columns: minmax(0, 1fr) minmax(520px, 38vw);
  }

  .detail .large {
    width: 100%;
  }
}

@media (max-width: 1280px) {
  .detail {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 72px 0 18px;
  }

  .detail .large {
    width: 100vw;
    height: calc(100vh - 90px);
  }

  .detail .large img {
    width: auto !important;
    height: 100% !important;
    max-width: 100vw;
    max-height: 100%;
    object-fit: contain;
  }

  .analysis-card {
    width: calc(100vw - 20px);
    height: auto;
    margin: 0 10px;
  }
}

@media (max-width: 820px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .dialog-toolbar {
    top: 10px;
    right: 10px;
  }

  .icon-button {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
  }

  .controls {
    position: static;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary {
    grid-template-columns: repeat(3, 1fr);
  }

  .analysis-card {
    padding: 12px;
  }

  .detail .large {
    width: 100vw;
    height: auto;
  }

  .detail .large img {
    width: 100vw;
    height: auto;
    max-height: none;
  }
}

@media (max-width: 520px) {
  .dialog-toolbar {
    top: 8px;
    right: 8px;
  }
}

@media print {
  .controls,
  .topbar,
  .section-head button,
  dialog {
    display: none;
  }

  .layout {
    display: block;
  }

  .content {
    padding: 0;
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
  }
}
