:root {
  --bg: #f4f3ee;
  --surface: #ffffff;
  --surface-alt: #f8f7f3;
  --text: #182622;
  --muted: #5a6863;
  --border: #dcd8cd;
  --primary: #1b5e4b;
  --primary-hover: #14493a;
  --primary-light: #e6f2ee;
  --amber: #b86f20;
  --amber-light: #fdf4e7;
  --blue: #235789;
  --blue-light: #eaf1f8;
  --purple: #63458a;
  --purple-light: #f2edf8;
  --danger: #b9382c;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(24, 38, 34, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

/* TOPBAR */
.topbar {
  background: #132420;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 3px solid var(--primary);
}

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

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #27866b, #154d3d);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.5px;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-version {
  font-size: 11px;
  background: rgba(255,255,255,0.14);
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
  color: #bbe6d8;
}

.brand-subtitle {
  font-size: 12px;
  color: #9cb3ac;
}

.topbar-nav {
  display: flex;
  gap: 8px;
  background: rgba(255,255,255,0.07);
  padding: 4px;
  border-radius: 10px;
}

.mode-tab {
  background: transparent;
  border: none;
  color: #d0ddd9;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.mode-tab small {
  font-weight: 400;
  opacity: 0.78;
  font-size: 11.5px;
}

.mode-tab.active {
  background: #ffffff;
  color: #132420;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.tab-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.tab-dot.green { background: #29a37e; }
.tab-dot.blue { background: #3b82f6; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 99px;
  background: rgba(41, 163, 126, 0.18);
  color: #9ef0d4;
  border: 1px solid rgba(41, 163, 126, 0.35);
}

.sync-pill.saving {
  background: rgba(245, 158, 11, 0.22);
  color: #fde68a;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
}

.btn-top {
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-excel {
  background: #237a57;
  color: #fff;
}
.btn-excel:hover { background: #1c6346; }

.btn-outline {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.22);
}
.btn-outline:hover { background: rgba(255,255,255,0.18); }

/* KPI RIBBON */
.kpi-ribbon {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 14px 24px;
  background: #e9e6dd;
  border-bottom: 1px solid var(--border);
}

.kpi-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
}

.kpi-item.highlight-green {
  border-left: 5px solid var(--primary);
  background: #f5fbf9;
}

.kpi-item.highlight-amber {
  border-left: 5px solid var(--amber);
  background: #fffaf3;
}

.kpi-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

.kpi-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin: 2px 0;
}

.kpi-item small {
  font-size: 11.5px;
  color: var(--muted);
}

/* MAIN VIEWS & SUBNAVS */
.main-view {
  display: none;
  padding: 18px 24px 48px;
  max-width: 1560px;
  margin: 0 auto;
}
.main-view.active {
  display: block;
}

.subnav-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.subtab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.subtab i {
  font-style: normal;
  font-size: 11.5px;
  font-weight: 800;
  background: var(--primary);
  color: #fff;
  padding: 2px 7px;
  border-radius: 6px;
}

.subtab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.subtab.active i {
  background: rgba(255,255,255,0.22);
}

.sub-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: rgba(0,0,0,0.08);
}
.subtab.active .sub-badge {
  background: rgba(255,255,255,0.22);
}

.saha-panel, .analiz-panel {
  display: none;
}
.saha-panel.active, .analiz-panel.active {
  display: block;
}

/* LAYOUT & CARDS */
.two-col-layout {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 18px;
  align-items: start;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.card h2, .card h3 {
  margin: 0 0 6px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

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

.card-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.tag-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  color: #fff;
  margin-right: 6px;
}
.tag-pill.green { background: var(--primary); }
.tag-pill.amber { background: var(--amber); }
.tag-pill.blue { background: var(--blue); }
.tag-pill.purple { background: var(--purple); }

.live-footprint-badge {
  background: var(--primary-light);
  border: 1px solid #b5dfd3;
  border-radius: 10px;
  padding: 8px 14px;
  text-align: right;
  min-width: 195px;
}
.live-footprint-badge span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
}
.live-footprint-badge strong {
  display: block;
  font-size: 19px;
  font-weight: 800;
  color: #0f3d30;
}
.live-footprint-badge small {
  font-size: 11px;
  color: var(--muted);
}

/* FORMS & GRIDS */
.form-section-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--primary);
  background: var(--surface-alt);
  padding: 7px 12px;
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  margin: 16px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; align-items: end; margin-bottom: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; align-items: end; margin-bottom: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; align-items: end; margin-bottom: 10px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px 12px; align-items: end; margin-bottom: 10px; }

.field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: #2c3e38;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  line-height: 38px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(27, 94, 75, 0.15);
}

.input-sm {
  width: 170px !important;
  padding: 6px 10px !important;
  font-size: 12.5px !important;
}

.mutat-banner, .intensive-box {
  background: var(--amber-light);
  border: 1px solid #f0d4b0;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.intensive-box {
  background: var(--purple-light);
  border-color: #d6c6eb;
  margin-top: 12px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.template-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.tpl-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
  transition: all 0.15s;
}

.tpl-chip:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.tpl-chip input {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
}

.helper-note {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.form-actions {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-large {
  padding: 12px 22px;
  font-size: 15px;
}

.btn-mini {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #b5dfd3;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn-mini:hover { background: #d4ebe3; }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.btn-del-row {
  background: #fee2e2;
  color: #991b1b;
  border: none;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 11.5px;
  cursor: pointer;
  font-weight: 600;
}

.autosave-hint {
  font-size: 12px;
  color: var(--muted);
}

/* PATIENT MINI CARD */
.patient-mini-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
}

.patient-mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-top: 8px;
}

/* TABLES */
.table-scroll {
  overflow-x: auto;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: #2c3e38;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table.compact th, .data-table.compact td {
  padding: 6px 8px;
  font-size: 12.5px;
}

.data-table tbody tr:hover {
  background: #f5f9f7;
}

.clickable-row {
  cursor: pointer;
}

/* CHARTS & VISUALIZATIONS */
.chart-box {
  min-height: 270px;
  padding: 8px 0;
}

.chart-box-large {
  min-height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bar-row {
  margin-bottom: 10px;
}
.bar-label-line {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 3px;
}
.bar-track {
  height: 12px;
  background: #e9e6dd;
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease;
}

.mc-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.mc-stat-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.mc-stat-box small {
  display: block;
  font-size: 11px;
  color: var(--muted);
}
.mc-stat-box strong {
  font-size: 16px;
  color: var(--primary);
}

.ba-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ba-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.boundary-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.boundary-group {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.boundary-group.included {
  background: #f2fbf7;
  border-color: #b7e2d1;
}
.boundary-group.excluded {
  background: #fdf5f5;
  border-color: #f1c5c5;
}
.boundary-group h4 {
  margin: 0 0 8px;
}
.boundary-group ul {
  margin: 0;
  padding-left: 18px;
}
.boundary-group li {
  margin-bottom: 6px;
  font-size: 12.5px;
}

/* MODAL & TOAST */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: #fff;
  padding: 24px;
  border-radius: 14px;
  max-width: 460px;
  width: 92%;
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}
.modal-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #132420;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.2s;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .kpi-ribbon { grid-template-columns: repeat(3, 1fr); }
  .two-col-layout, .grid-2 { grid-template-columns: 1fr; }
  .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .kpi-ribbon { grid-template-columns: repeat(2, 1fr); padding: 10px 12px; }
  .main-view { padding: 12px; }
  .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
}
