/* ===================== MediBill Klinik — Prototyp Stylesheet ===================== */

:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --text: #0f1b2d;
  --text-muted: #5b6b82;
  --primary: #0d6b78;
  --primary-dark: #084650;
  --primary-light: #e4f3f3;
  --accent: #2f8f9d;
  --success: #1a8754;
  --success-bg: #e6f6ee;
  --warning: #b4790c;
  --warning-bg: #fdf1dc;
  --danger: #c0392b;
  --danger-bg: #fbe9e7;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 27, 45, 0.08);
  --shadow-lg: 0 20px 48px rgba(15, 27, 45, 0.14);
  --sidebar-w: 248px;
  --topbar-h: 68px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
html[dir="rtl"] body { font-family: var(--font); }
body { font-size: 15px; line-height: 1.5; }
button { font-family: inherit; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}
html[dir="rtl"] .app {
  grid-template-columns: 1fr var(--sidebar-w);
  grid-template-areas:
    "topbar sidebar"
    "main sidebar";
}

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  background: linear-gradient(185deg, var(--primary-dark), #0a3a44 85%);
  color: #eaf5f5;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #38b7a4, #1d7c87);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: white;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: 0.2px; }
.brand-text span { display: block; font-size: 11.5px; color: #9fd4cf; }

.nav-group { margin-top: 10px; }
.nav-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7fb9b4;
  padding: 10px 12px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: #d7ece9;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: inherit;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.16); color: #fff; }
.nav-link.active svg { opacity: 1; }
.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  font-size: 11.5px;
  color: #7fb9b4;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* ---------- Topbar ---------- */
.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-search {
  flex: 1;
  max-width: 420px;
  position: relative;
}
.topbar-search input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 13.5px;
  color: var(--text);
}
html[dir="rtl"] .topbar-search input { padding: 9px 38px 9px 14px; }
.topbar-search svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-muted);
}
html[dir="rtl"] .topbar-search svg { left: auto; right: 13px; }
.topbar-search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.lang-switch { position: relative; }
.lang-switch-btn {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.lang-switch-btn:hover { border-color: var(--accent); }
.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 190px;
  display: none;
  z-index: 50;
}
html[dir="rtl"] .lang-menu { right: auto; left: 0; }
.lang-menu.open { display: block; }
.lang-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
  text-align: inherit;
}
.lang-menu button:hover { background: var(--surface-soft); }
.lang-menu button.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.flag { font-size: 16px; }

.user-pill {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}
html[dir="rtl"] .user-pill { padding: 5px 5px 5px 12px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--primary-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700;
}
.user-pill span { font-size: 13px; font-weight: 600; }

/* ---------- Main ---------- */
.main {
  grid-area: main;
  padding: 26px 30px 60px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-head { margin-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 23px; font-weight: 700; letter-spacing: -0.2px; }
.page-head p { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

/* ---------- Cards / KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 980px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.kpi-card .kpi-value { font-size: 27px; font-weight: 700; margin-top: 6px; letter-spacing: -0.5px; }
.kpi-card .kpi-sub { font-size: 12px; color: var(--success); margin-top: 4px; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }

.activity-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--primary-light); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.activity-item .meta { color: var(--text-muted); font-size: 12px; }
.activity-item strong { font-weight: 600; }

.quick-btn {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  width: 100%;
  margin-bottom: 10px;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.quick-btn:hover { border-color: var(--accent); background: var(--primary-light); }
.quick-btn svg { width: 17px; height: 17px; color: var(--primary); flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-soft { background: var(--primary-light); color: var(--primary-dark); }
.btn-soft:hover { background: #d4ebea; }
.btn-danger-ghost { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: start;
  padding: 13px 16px;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-soft); }
.cell-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-private { background: #eef0fb; color: #4747c7; }
.badge-public { background: var(--primary-light); color: var(--primary-dark); }
.badge-draft { background: var(--surface-soft); color: var(--text-muted); }
.badge-submitted { background: var(--warning-bg); color: var(--warning); }
.badge-paid { background: var(--success-bg); color: var(--success); }
.lang-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

/* ---------- Forms ---------- */
label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
select, input[type="text"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
  color: var(--text);
  font-family: inherit;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--primary-light); }
textarea { resize: vertical; min-height: 78px; line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .field-row { grid-template-columns: 1fr; } }

/* ---------- Billing view ---------- */
.billing-layout { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .billing-layout { grid-template-columns: 1fr; } }
.catalog-list { max-height: 560px; overflow-y: auto; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.catalog-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}
.catalog-item .ci-main { font-size: 13px; }
.catalog-item .ci-ziffer { font-weight: 700; color: var(--primary-dark); margin-inline-end: 6px; }
.catalog-item .ci-cat { font-size: 11px; color: var(--text-muted); }
.catalog-item .ci-price { font-size: 12.5px; font-weight: 700; white-space: nowrap; }

.invoice-doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
}
.invoice-doc-head { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 18px; border-bottom: 2px solid var(--primary); margin-bottom: 18px; }
.invoice-doc-head h2 { font-size: 20px; color: var(--primary-dark); }
.invoice-doc-head .meta-right { text-align: end; font-size: 13px; color: var(--text-muted); }
.invoice-patient-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; font-size: 13px; }
.invoice-patient-grid div span { display: block; color: var(--text-muted); font-size: 11.5px; margin-bottom: 2px; }
.sum-row { display: flex; justify-content: flex-end; gap: 28px; padding-top: 14px; font-size: 14px; }
.sum-row.total { font-size: 18px; font-weight: 700; color: var(--primary-dark); border-top: 2px solid var(--primary); margin-top: 6px; padding-top: 14px; }
.empty-state { text-align: center; padding: 34px 16px; color: var(--text-muted); font-size: 13.5px; }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: 0.5; }

/* ---------- Letters view ---------- */
.letter-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .letter-layout { grid-template-columns: 1fr; } }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tag-chip { display: flex; align-items: center; gap: 7px; background: var(--primary-light); color: var(--primary-dark); padding: 6px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.tag-chip button { border: none; background: transparent; cursor: pointer; color: var(--primary-dark); font-size: 13px; line-height: 1; padding: 0; }
.snippet-btn {
  display: block; width: 100%; text-align: start;
  padding: 9px 12px; margin-bottom: 7px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  background: var(--surface-soft); color: var(--text); font-size: 12.5px;
  cursor: pointer;
}
.snippet-btn:hover { border-color: var(--accent); background: var(--primary-light); }
.med-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
@media (max-width: 700px) { .med-row { grid-template-columns: 1fr 1fr; } }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--danger); flex-shrink: 0; }
.icon-btn:hover { background: var(--danger-bg); border-color: var(--danger); }

.letter-doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 34px;
  font-size: 13.5px;
  line-height: 1.7;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  max-height: calc(100vh - var(--topbar-h) - 40px);
  overflow-y: auto;
}
.letter-doc .ld-letterhead { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 16px; }
.letter-doc .ld-letterhead h2 { font-size: 17px; color: var(--primary-dark); }
.letter-doc .ld-letterhead small { color: var(--text-muted); font-size: 11.5px; }
.letter-doc h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--primary); margin: 16px 0 6px; }
.letter-doc p { white-space: pre-wrap; }
.letter-doc .ld-sign { margin-top: 22px; font-size: 13px; }
.letter-doc table { font-size: 12.5px; }
.letter-doc .ld-diag-item { margin-bottom: 2px; }

/* ---------- Modal / Toast ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 20, 35, 0.45);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-width: 620px; width: 100%; max-height: 86vh; overflow-y: auto; padding: 26px 28px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; }
.modal-close { border: none; background: var(--surface-soft); width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 16px; color: var(--text-muted); }

.toast-wrap { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
html[dir="rtl"] .toast-wrap { right: auto; left: 22px; }
.toast {
  background: var(--primary-dark); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Settings ---------- */
.settings-grid { display: grid; gap: 18px; max-width: 560px; }

/* ---------- Print ---------- */
@media print {
  body * { visibility: hidden; }
  .print-doc, .print-doc * { visibility: visible; }
  .print-doc { position: absolute; top: 0; left: 0; width: 100%; padding: 0; margin: 0; border: none; box-shadow: none; max-height: none; overflow: visible; }
  .no-print { display: none !important; }
}

/* ---------- Scrollbars (subtle) ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #c9d4e0; border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive sidebar collapse ---------- */
@media (max-width: 860px) {
  :root { --sidebar-w: 72px; }
  .brand-text, .nav-label, .nav-link span { display: none; }
  .nav-link { justify-content: center; }
  .brand { justify-content: center; padding: 6px 0 20px; }
  .main { padding: 20px 14px 50px; }
  .topbar { padding: 0 14px; }
  .topbar-search { display: none; }
}
