:root {
  --navy: #16233d;
  --navy-2: #1e2f52;
  --gold: #b8934a;
  --gold-light: #e8d9b8;
  --cream: #faf6ec;
  --paper: #fdfcf9;
  --ink: #1a1a1a;
  --ink-soft: #5c584e;
  --line: #e2dfd6;
  --green: #2f6b4f;
  --red: #a13d3d;
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app-shell { display: flex; min-height: 100vh; }
.hidden { display: none !important; }

/* ---------------- Rail / Sidebar ---------------- */
.rail {
  width: 236px;
  flex-shrink: 0;
  background: var(--navy);
  color: #f4f1ea;
  display: flex;
  flex-direction: column;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.rail-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 34px; }
.rail-brand .mark {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--gold);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--gold);
  border-radius: 4px;
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: 0.01em; }
.brand-sub { font-size: 11px; color: #a9b3c7; margin-top: 1px; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.rail-item {
  text-align: left;
  background: none;
  border: none;
  color: #cdd4e2;
  font-family: var(--font-ui);
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.rail-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.rail-item.is-active { background: var(--gold); color: var(--navy); font-weight: 600; }

.rail-foot { border-top: 1px solid rgba(255,255,255,0.14); padding-top: 16px; }
.ytd-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: #a9b3c7; margin-bottom: 8px; }
.ytd-bar { height: 6px; background: rgba(255,255,255,0.12); border-radius: 4px; overflow: hidden; }
.ytd-bar-fill { height: 100%; background: var(--gold); transition: width 0.4s ease; }
.ytd-value { font-family: var(--font-mono); font-size: 11px; margin-top: 6px; color: #e8e4d8; }

/* ---------------- Main ---------------- */
.main { flex: 1; padding: 36px 44px; max-width: 1180px; }
.view-head { margin-bottom: 26px; }
.view-head h1 { font-family: var(--font-display); font-size: 27px; font-weight: 600; margin: 0 0 6px; }
.view-head p { margin: 0; color: var(--ink-soft); font-size: 13.5px; }
.view-head code { background: var(--gold-light); padding: 1px 6px; border-radius: 3px; font-family: var(--font-mono); font-size: 12px; }

/* ---------------- Stat cards ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat-card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); margin-bottom: 10px; }
.stat-value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; }
.stat-value.accent { color: var(--gold); }

.panel-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.panel h3 { font-family: var(--font-display); font-size: 15.5px; margin: 0 0 14px; font-weight: 600; }
.bp-rows { display: flex; flex-direction: column; gap: 10px; }
.bp-row { display: flex; justify-content: space-between; font-size: 13px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.bp-row .tag { font-family: var(--font-mono); }
.expiring-list { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.expiring-item { display: flex; justify-content: space-between; }
.badge-status { font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 3px; }
.badge-status.soon { background: #f4e3c4; color: #8a5a1a; }
.badge-status.expired { background: #f4d4d4; color: var(--red); }
.badge-status.active { background: #d9ead9; color: var(--green); }
.badge-status.hold { background: #e3ddf0; color: #5b4b8a; }

.status-select {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
.status-select.active { background: #d9ead9; color: var(--green); border-color: #b9dab9; }
.status-select.soon { background: #f4e3c4; color: #8a5a1a; border-color: #e6c88a; }
.status-select.expired { background: #f4d4d4; color: var(--red); border-color: #e6b3b3; }
.status-select.hold { background: #e3ddf0; color: #5b4b8a; border-color: #cabfe6; }

.view-head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.view-head-row .btn-primary { flex-shrink: 0; white-space: nowrap; }

.add-panel {
  background: var(--paper);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 18px;
}
.add-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field-span2 { grid-column: span 2; }
.add-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.form-msg { margin: 10px 0 0; font-size: 12px; }
.form-msg.error { color: var(--red); }
.form-msg.success { color: var(--green); }

@media (max-width: 640px) {
  .add-grid { grid-template-columns: 1fr; }
  .field-span2 { grid-column: span 1; }
}

/* ---------------- Tables ---------------- */
.table-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; background: var(--navy); color: #f0ede4; padding: 11px 16px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.data-table td { padding: 11px 16px; border-bottom: 1px solid var(--line); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.mono { font-family: var(--font-mono); }
.doc-links a { color: var(--navy); text-decoration: none; font-size: 12px; margin-right: 10px; border-bottom: 1px dotted var(--gold); }
.doc-links a:hover { color: var(--gold); }

/* ---------------- Composer / Generator ---------------- */
.composer { display: grid; grid-template-columns: 380px 1fr; gap: 22px; align-items: start; }
.composer-form { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-width: 0; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: 13.5px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
.field input:disabled { background: var(--cream); color: var(--ink-soft); cursor: not-allowed; font-family: var(--font-mono); }
.input-idr { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; overflow: hidden; }
.input-idr span { padding: 0 10px; font-family: var(--font-mono); color: var(--ink-soft); background: var(--cream); align-self: stretch; display: flex; align-items: center; font-size: 13px; }
.input-idr input { border: none; flex: 1; font-family: var(--font-mono); }
.input-idr input:focus { outline: none; }

.scheme-toggle { display: flex; gap: 6px; }
.scheme-toggle button {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 11.5px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-soft);
}
.scheme-toggle button.is-active { background: var(--navy); color: #fff; border-color: var(--navy); }
.hint { font-size: 11.5px; color: var(--ink-soft); margin: 0; line-height: 1.4; }

.btn-primary {
  background: var(--gold);
  color: var(--navy);
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 14px;
  cursor: pointer;
  height: 100%;
}
.btn-primary:hover { background: #a67f3c; }
.btn-ghost { background: none; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; padding: 6px 12px; cursor: pointer; color: var(--navy); }
.btn-ghost:hover { border-color: var(--navy); }
.btn-danger { background: none; border: 1px solid var(--red); border-radius: 6px; font-size: 11.5px; padding: 5px 10px; cursor: pointer; color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.actions-cell { text-align: right; white-space: nowrap; }

.calc-readout { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 4px; }
.calc-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; font-family: var(--font-mono); }
.calc-row.highlight { font-weight: 700; color: var(--green); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.calc-flags { margin: 10px 0 0; }
.flag-meterai { display: inline-block; background: var(--gold); color: var(--navy); font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 3px; }
.flag-ok { display: inline-block; background: #d9ead9; color: var(--green); font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 3px; }
.calc-warnings { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.calc-warnings li { font-size: 11px; color: #8a5a1a; background: #fbf1dc; border-left: 2px solid var(--gold); padding: 6px 8px; border-radius: 3px; }

.composer-preview { position: sticky; top: 36px; }
.preview-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 12.5px; color: var(--ink-soft); }
.preview-actions { display: flex; gap: 8px; }
.preview-paper { background: #fff; border-radius: 8px; box-shadow: 0 8px 28px rgba(22,35,61,0.14); overflow: hidden; height: 720px; }
.preview-paper iframe { width: 100%; height: 100%; border: none; }

@media (max-width: 980px) {
  .composer { grid-template-columns: 1fr; }
  .composer-preview { position: static; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
