:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #dbe7ff;
  --danger: #c2410c;
  --good: #15803d;
  --warn: #b45309;
  --bar: #3b82f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2c333d;
    --text: #e6e9ee;
    --muted: #97a1ae;
    --accent: #4f8cff;
    --accent-text: #0b1220;
    --accent-soft: #1d2b45;
    --danger: #f08a5d;
    --good: #4ade80;
    --warn: #fbbf24;
    --bar: #4f8cff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--danger); margin: 8px 0 0; }

button, .button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.07); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.danger { color: var(--danger); }
button.small { padding: 3px 9px; font-size: 13px; }
button:disabled { opacity: .6; cursor: default; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Giriş */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; box-shadow: var(--shadow);
  display: grid; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-weight: 500; }
.login-card button { justify-content: center; padding: 10px; }

/* Üst bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
#nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted);
  text-decoration: none; white-space: nowrap; font-weight: 500;
}
#nav a:hover { background: var(--surface-2); color: var(--text); }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
.user { display: flex; align-items: center; gap: 4px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.page-head h1 { margin: 0; font-size: 22px; flex: 1; min-width: 200px; }
.help { margin: 0 0 14px; color: var(--muted); max-width: 820px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input { max-width: 280px; }
.toolbar select { width: auto; }

/* Tablo */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.pill.good { color: var(--good); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--danger); }

/* Panel */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12.5px; }
.section-title { font-size: 17px; margin: 26px 0 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }
.card table th, .card table td { padding: 6px 8px; }
.card tbody tr { cursor: default; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 40px; align-items: center; gap: 8px; margin: 5px 0; font-size: 14px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--bar); border-radius: 5px; }
.notice {
  background: var(--accent-soft); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
}

/* Dialog */
dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(10, 14, 20, .5); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 18px; flex: 1; }
.dialog-body {
  padding: 16px 18px; overflow-y: auto;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px;
}
.dialog-body .field { display: grid; gap: 5px; min-width: 0; }
.dialog-body .field.wide { grid-column: 1 / -1; }
.dialog-body .field > span { font-size: 13.5px; font-weight: 500; }
.dialog-body .field > span .req { color: var(--danger); }
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; min-width: 0; }
.rating { display: flex; gap: 4px; }
.rating button { flex: 1; justify-content: center; padding: 7px 0; }
.rating button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.dialog-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.dialog-foot .error { margin: 0; }
#dialog-error { padding: 0 18px; }
.meta { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 20;
}

/* Telefon */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  #nav { order: 3; flex-basis: 100%; }
  .user { margin-left: auto; }
  main { padding: 16px; }
  .toolbar input, .toolbar select { max-width: none; flex: 1 1 140px; }
  .dialog-body { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 34px; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Kayıt tabloları telefonda kart görünümüne geçer */
  .records thead { display: none; }
  .records, .records tbody, .records tr, .records td { display: block; width: 100%; }
  .records tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .records td { border: 0; padding: 3px 14px; display: flex; gap: 10px; }
  .records td::before { content: attr(data-label); color: var(--muted); font-size: 13px; min-width: 110px; }
  .records td.actions-cell::before { content: none; }
  .records .row-actions { justify-content: flex-start; }
}

/* Klinik bul / Rehber */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.template { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.template-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.template p { margin: 6px 0 0; }
.card ol, .card ul { margin: 0; padding-left: 20px; }
.card li { margin: 4px 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
.rating button { min-width: 0; padding-left: 0; padding-right: 0; }
