:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #12201d;
  --muted: #66736f;
  --line: #dfe7e3;
  --brand: #0f766e;
  --brand-2: #d97706;
  --accent: #2563eb;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(16, 35, 31, 0.12);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

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, textarea {
  font: inherit;
}

input[readonly] {
  background: #f8faf9;
  color: var(--muted);
}

button, .file-btn {
  border: 0;
  background: var(--brand);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 42px;
  cursor: pointer;
  font-weight: 700;
}

button:hover, .file-btn:hover { filter: brightness(0.96); }

.ghost {
  background: #e9f2ef;
  color: var(--brand);
}

.link-btn {
  background: transparent;
  color: var(--brand);
  padding-inline: 0;
  min-height: auto;
  text-align: left;
}

.link-btn:hover {
  text-decoration: underline;
  filter: none;
}

.danger {
  background: var(--danger);
}

.topbar {
  min-height: 118px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 24px clamp(16px, 4vw, 42px);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.94), rgba(36, 74, 68, 0.94)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='80' viewBox='0 0 160 80'%3E%3Cpath d='M0 70 C45 20 85 95 160 26' stroke='%23ffffff' stroke-opacity='.16' stroke-width='8' fill='none'/%3E%3Ccircle cx='128' cy='22' r='9' fill='%23f59e0b' fill-opacity='.42'/%3E%3C/svg%3E");
  color: white;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  opacity: 0.9;
}

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

.top-actions select {
  border-color: rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.96);
}

.file-btn input {
  display: none;
}

.storage-status {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(255,255,255,0.16);
  color: white;
  font-weight: 800;
  font-size: 0.86rem;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px clamp(12px, 4vw, 42px);
  background: white;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 4;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  border: 1px solid transparent;
}

.tabs button.active {
  color: var(--brand);
  background: #eef7f4;
  border-color: #cfe8e2;
}

main {
  padding: 24px clamp(12px, 4vw, 42px) 48px;
}

.chart-tooltip {
  position: absolute;
  z-index: 50;
  max-width: 240px;
  padding: 9px 11px;
  background: rgba(18, 32, 29, 0.94);
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.88rem;
  line-height: 1.35;
}

.chart-tooltip.hidden {
  display: none;
}

.view { display: none; }
.view.active { display: block; }

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

.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(16, 35, 31, 0.04);
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.25rem, 2vw, 1.8rem);
}

.dashboard-grid, .form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

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

.panel {
  padding: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
}

.panel-head span, .muted {
  color: var(--muted);
}

label {
  display: grid;
  gap: 6px;
  color: #30423d;
  font-weight: 700;
  font-size: 0.9rem;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 9px 11px;
  background: white;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

.stack {
  display: grid;
  gap: 12px;
}

.two-col, .filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.filters {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
}

.quick-range, .security-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-range button {
  background: #eef3f1;
  color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

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

th {
  color: var(--muted);
  font-size: 0.82rem;
}

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

.row-actions button, .chip button {
  min-height: 0;
  padding: 6px 9px;
}

.row-actions .edit {
  background: var(--accent);
}

.row-actions .delete, .chip button {
  background: #fee4e2;
  color: var(--danger);
}

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

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.list-item strong {
  display: block;
}

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

.master-editor {
  display: grid;
  gap: 12px;
}

.master-editor form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.master-editor form.item-add-form {
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 220px) auto;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  background: #f2f5f3;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 6px 6px 12px;
}

.item-link-list {
  display: grid;
  gap: 10px;
  flex-wrap: initial;
}

.item-link-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 220px) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.item-link-row input,
.item-link-row select {
  min-height: 38px;
}

.item-link-row button {
  min-height: 38px;
  padding: 8px 11px;
}

.item-link-row .edit {
  background: var(--accent);
}

.item-link-row .delete {
  background: #fee4e2;
  color: var(--danger);
}

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

.summary-line {
  padding: 12px;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lock-screen {
  position: fixed;
  inset: 0;
  background: rgba(11, 22, 20, 0.86);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 18px;
}

.lock-screen.hidden {
  display: none;
}

.lock-panel {
  width: min(420px, 100%);
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.lock-panel h1, .lock-panel p {
  margin: 0;
}

.auth-pane,
.auth-pane form {
  display: grid;
  gap: 12px;
}

@media (max-width: 900px) {
  .summary-grid, .dashboard-grid, .form-grid, .masters-grid, .filters, .report-summary {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (min-width: 900px) {
  body {
    display: grid;
    grid-template-columns: 246px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    min-height: 100vh;
  }

  .topbar {
    grid-column: 1 / -1;
    min-height: 104px;
    padding-block: 20px;
  }

  .tabs {
    grid-column: 1;
    grid-row: 2;
    position: sticky;
    top: 0;
    height: calc(100vh - 104px);
    align-self: start;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 18px 14px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .tabs button {
    justify-content: flex-start;
    text-align: left;
    width: 100%;
  }

  main {
    grid-column: 2;
    grid-row: 2;
    padding: 26px 30px 48px;
    max-width: 1440px;
    width: 100%;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(160px, 1fr));
  }

  .panel {
    box-shadow: 0 8px 24px rgba(16, 35, 31, 0.06);
  }
}

@media (max-width: 560px) {
  main {
    padding-inline: 10px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .master-editor form.item-add-form,
  .item-link-row {
    grid-template-columns: 1fr;
  }

  .panel, .metric {
    padding: 14px;
  }
}
