:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2128;
  --muted: #6b7380;
  --line: #dfe3e8;
  --accent: #104c54;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1f2;
  --ok: #1f7a4d;
  --ok-soft: #e4f4ec;
  --warn: #9a6200;
  --warn-soft: #fdf3dd;
  --err: #b42318;
  --err-soft: #fdecea;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
h2 { font-size: 15px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.optional { color: var(--muted); font-weight: 400; }

/* düğmeler & form */
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9c1ca; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #172f49; }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }

label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
input, select, textarea {
  font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.invalid { border-color: var(--err); }
textarea { resize: vertical; }
.inline { display: flex; gap: 8px; }
.hint { font-weight: 400; color: var(--muted); min-height: 1em; }
.hint.bad { color: var(--err); }
.form-error { color: var(--err); margin: 0; font-weight: 600; }

/* giriş */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }

/* üst çubuk */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { font: inherit; font-weight: 600; background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user { font-weight: 600; }
.agent-pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.agent-pill.ok { background: var(--ok-soft); color: var(--ok); }
.agent-pill.bad { background: var(--err-soft); color: var(--err); }

.view { padding: 24px; max-width: 1280px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

/* istem formu */
.grid { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; align-items: start; }
.row { margin-bottom: 12px; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; }
.actions .form-error { margin-right: auto; }

.tests-card { display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.tests-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.tests-head h2 { margin: 0; }
.tests-head input { max-width: 320px; margin-left: auto; }
.selected { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; background: var(--bg); border-radius: 8px; min-height: 44px; margin-bottom: 12px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: #fff; border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 12.5px; font-weight: 600; }
.chip button { border: 0; background: rgba(255,255,255,.2); color: #fff; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 12px; line-height: 1; }
.test-list { overflow: auto; flex: 1; columns: 2 260px; column-gap: 20px; }
.test-group { break-inside: avoid; margin-bottom: 14px; }
.test-group h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.test-item { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 400; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.test-item:hover { background: var(--bg); }
.test-item input { width: auto; margin: 0; }
.test-item code { color: var(--muted); font-size: 11.5px; margin-left: auto; }

/* liste */
.list-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.list-head h2 { margin: 0; }
.filters { margin-left: auto; display: flex; gap: 8px; }
.filters input { width: 240px; }
.filters select { width: auto; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #fafbfc; }
table.list td.actions-cell { text-align: right; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; }
.empty { text-align: center; padding: 30px 0; margin: 0; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge.awaiting_signature { background: var(--warn-soft); color: var(--warn); }
.badge.signed { background: var(--accent-soft); color: var(--accent); }
.badge.processing { background: var(--accent-soft); color: var(--accent); }
.badge.entered { background: var(--ok-soft); color: var(--ok); }
.badge.error { background: var(--err-soft); color: var(--err); }
.badge.cancelled { background: var(--bg); color: var(--muted); }

/* pencere */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 26, .5); display: grid; place-items: center; z-index: 20; padding: 20px; }
.modal-box { background: var(--card); border-radius: 14px; width: min(1100px, 100%); height: min(860px, 100%); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { flex: 1; display: grid; grid-template-columns: 1fr 320px; min-height: 0; }
.modal-body iframe { width: 100%; height: 100%; border: 0; background: #e9ecef; }
.modal-side { padding: 18px; border-left: 1px solid var(--line); overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.modal-side dt { color: var(--muted); }
.modal-side dd { margin: 0; font-weight: 600; word-break: break-word; }
.modal-side .side-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.notice { padding: 10px 12px; border-radius: 8px; font-size: 13px; background: var(--bg); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.bad { background: var(--err-soft); color: var(--err); }
.notice.info { background: var(--accent-soft); color: var(--accent); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 8px; font-weight: 600; z-index: 30; max-width: 90vw; }
.toast.bad { background: var(--err); }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .tests-card { max-height: none; }
  .test-list { columns: 1; max-height: 50vh; }
  .modal-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .modal-side { border-left: 0; border-top: 1px solid var(--line); }
  .topbar { padding: 10px 16px; gap: 12px; }
  .view { padding: 16px; }
  .filters { margin-left: 0; width: 100%; }
  .filters input { width: 100%; }
  .col-doctor { display: none; }
}

/* kaşe */
.dialog { background: var(--card); border-radius: 14px; width: min(480px, 100%); overflow: hidden; }
.dialog-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.dialog-body .muted { margin: 0; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.stamp-preview { min-height: 140px; border: 1px dashed var(--line); border-radius: 10px; display: grid; place-items: center; padding: 12px;
  background: repeating-conic-gradient(#f3f4f6 0% 25%, #fff 0% 50%) 50% / 16px 16px; }
.stamp-preview img { max-width: 100%; max-height: 200px; }
.stamp-warn { margin: 0 auto 0 0; color: var(--warn); font-size: 13px; font-weight: 600; }
.linkish { font: inherit; font-weight: 700; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
label.btn { display: inline-flex; flex-direction: row; font-size: 14px; }

/* marka */
.brand { gap: 12px; }
.brand-logo { height: 40px; width: auto; display: block; }
.brand > small { color: var(--muted); font-size: 12.5px; font-weight: 600; border-left: 1px solid var(--line); padding-left: 12px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 10px; border-bottom: 3px solid var(--accent); }
.login-brand img { height: 84px; width: auto; }
.login-brand small { color: var(--muted); font-weight: 600; }
.topbar { border-bottom: 3px solid var(--accent); }

/* form düzeni */
.col { display: flex; flex-direction: column; gap: 20px; }
.row.two.wide-first { grid-template-columns: 2fr 1fr; }

/* ICD-10 arama */
.icd-box { position: relative; display: block; }
.icd-results { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(15, 20, 26, .12); max-height: 280px; overflow: auto; display: block; }
.icd-item { display: flex; gap: 10px; padding: 8px 10px; cursor: pointer; font-weight: 400; font-size: 13.5px; }
.icd-item:hover, .icd-item.active { background: var(--accent-soft); }
.icd-item b { min-width: 52px; color: var(--accent); }
.icd-empty { padding: 10px; color: var(--muted); font-weight: 400; font-size: 13px; }
.dx-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.dx { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); border-radius: 8px; padding: 6px 6px 6px 10px; font-size: 13.5px; }
.dx b { color: var(--accent); min-width: 48px; }
.dx span { flex: 1; }
.dx button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; }

/* elle test */
.custom-test { display: flex; gap: 8px; padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--line); }
.chip.custom { background: #172f49; }
.chip.custom::before { content: "✎"; margin-right: 2px; }

@media (max-width: 900px) {
  .row.two.wide-first { grid-template-columns: 1fr; }
  .brand > small { display: none; }
}

/* ajan uyarı bandı */
.agent-help { background: var(--warn-soft); color: #5c3b00; border-bottom: 1px solid #f0d9a8; padding: 10px 24px; font-size: 13.5px; line-height: 1.5; }
.agent-help b { color: #4a2f00; }
