:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f3f6f8;
  --surface-3: #e8eef2;
  --text: #18232c;
  --muted: #66727e;
  --line: #d8e1e7;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --accent: #b45309;
  --info: #2563eb;
  --danger: #b91c1c;
  --warn: #ca8a04;
  --ok: #15803d;
  --ink: #263541;
  --sidebar: #1d2930;
  --sidebar-2: #273740;
  --shadow: 0 14px 34px rgba(31, 41, 55, 0.08);
  --shadow-soft: 0 1px 2px rgba(31, 41, 55, 0.05);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #f8fafc;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: #d9f4ef;
  color: #0f766e;
  border-radius: 8px;
  font-weight: 800;
  box-shadow: inset 0 -1px 0 rgba(15, 118, 110, 0.18);
}

.brand-title {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0;
}

.brand-subtitle {
  color: #b6c2c9;
  font-size: 13px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d8e2e7;
  text-align: left;
  padding: 11px 12px 11px 14px;
  position: relative;
  transition: background-color 140ms ease, color 140ms ease;
}

.nav-item:hover,
.nav-item.active {
  background: var(--sidebar-2);
  color: #ffffff;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 999px;
  background: #38bdf8;
}

.status-box {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  background: #f0fdf9;
  border: 1px solid #bfe9dd;
  border-radius: 8px;
  min-height: 38px;
  max-width: 360px;
  padding: 0 12px;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
}

.status-dot.ok {
  background: var(--ok);
}

.status-dot.bad {
  background: var(--danger);
}

.main {
  padding: 26px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

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

h1 {
  font-size: 25px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  color: var(--ink);
}

h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

.topbar p,
.subtle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border-radius: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.primary-btn {
  background: var(--primary);
  color: #ffffff;
  padding: 0 16px;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--primary-strong);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

.ghost-btn {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  padding: 0 14px;
}

.ghost-btn:hover {
  background: var(--surface-2);
  border-color: #c5d2db;
}

.icon-btn {
  width: 36px;
  height: 36px;
  background: #ecfdf5;
  color: var(--ink);
  border-color: #b7e4d1;
  font-size: 20px;
  line-height: 1;
}

.icon-btn:hover {
  background: #d9fbe9;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.metric {
  padding: 15px 16px;
  display: grid;
  gap: 6px;
  border-top: 3px solid var(--primary);
}

.metric:nth-child(2) {
  border-top-color: var(--info);
}

.metric:nth-child(3) {
  border-top-color: var(--accent);
}

.metric:nth-child(4) {
  border-top-color: var(--ok);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 24px;
  line-height: 1.1;
  color: var(--ink);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.panel {
  padding: 17px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
  padding-bottom: 11px;
  border-bottom: 1px solid #edf2f5;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

label[hidden] {
  display: none;
}

.wide-field {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

textarea {
  min-height: 72px;
  resize: vertical;
  margin-bottom: 14px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
  background: #ffffff;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f4f7f9;
  text-transform: none;
}

tbody tr:hover {
  background: #fbfdfe;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.row-action {
  border: 1px solid transparent;
  color: var(--danger);
  background: transparent;
  padding: 4px 7px;
  border-radius: 6px;
}

.row-action:hover {
  background: #fef2f2;
  border-color: #fecaca;
}

.ai-run-status {
  margin: 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--muted);
  padding: 9px 11px;
  font-size: 13px;
  line-height: 1.4;
}

.ai-run-status.ok {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #166534;
}

.ai-run-status.warn {
  border-color: #fde68a;
  background: #fffbeb;
  color: #854d0e;
}

.advice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.8fr);
  gap: 16px;
}

.advice-box {
  background: #fbfdfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 210px;
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.7;
  box-shadow: inset 3px 0 0 rgba(15, 118, 110, 0.18);
}

.risk-list {
  background: #fffbeb;
  border: 1px solid #f5d487;
  border-radius: 8px;
  padding: 14px;
}

.risk-list ul {
  margin: 0;
  padding-left: 18px;
  color: #733d06;
  line-height: 1.6;
}

.qa-list {
  display: grid;
  gap: 10px;
}

.qa-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  padding: 12px;
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow-soft);
}

.qa-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.qa-question {
  font-weight: 700;
  color: var(--ink);
}

.qa-answer {
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
}

.qa-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfdfe;
}

.mode-pill,
.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  background: #e8f3f1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mode-pill {
  color: #0f5f58;
  background: #dcf7f1;
}

.tag.warn {
  color: #7c4a03;
  background: #fff3cf;
}

.tag.danger {
  color: #7f1d1d;
  background: #fee2e2;
}

.tag.ok {
  color: #14532d;
  background: #dcfce7;
}

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

.flow-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfe;
  display: grid;
  gap: 8px;
  border-left: 3px solid #9cc8ff;
}

.flow-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-weight: 700;
}

.flow-item p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

#cashChart {
  width: 100%;
  height: 320px;
  display: block;
  background: #fbfdfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 14px 16px;
  }

  .nav {
    display: flex;
    min-width: max-content;
  }

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

@media (max-width: 760px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .sidebar {
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
    padding: 16px;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .metrics,
  .form-grid,
  .form-grid.compact,
  .flow-list {
    grid-template-columns: 1fr;
  }

  .brand-subtitle {
    display: none;
  }

  .status-box {
    flex: 1 0 100%;
    max-width: none;
    width: 100%;
  }

  .brand > div:not(.brand-mark) {
    display: none;
  }

  .brand {
    flex: 0 0 auto;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }
}
