/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e3e1dc;
  --text: #1b1a18;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #c22f48;
  --accent-hover: #a82539;
  --accent-ink: #ffffff;
  --accent-soft: #fbe8eb;
  --focus: #2a78d6;

  /* grafik serileri (dataviz referans paleti, slot 1-2-3) */
  --sys: #2a78d6;
  --dia: #eb6834;
  --pulse: #1baf7a;
  --ref: #9a9993;
  --grid: #ebe9e4;

  /* durum renkleri — her zaman etiketle birlikte kullanılır */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --low: #4a3aa7;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --tabbar-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #34342f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #e5566d;
    --accent-hover: #ee6f83;
    --accent-ink: #ffffff;
    --accent-soft: #3a1d23;
    --focus: #6da7ec;
    --sys: #3987e5;
    --dia: #d95926;
    --pulse: #199e70;
    --ref: #77766f;
    --grid: #2a2a27;
    --low: #9085e9;
    --shadow: none;
  }
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { opacity: .6; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); opacity: 1; } }

/* ------------------------------------------------------------------ fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 14px; font-weight: 600; color: var(--text-2); }
.field input, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .value-field input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }

.form-error { color: var(--critical); font-weight: 600; font-size: 14px; min-height: 0; margin: 0 0 10px; }
.form-error:empty { display: none; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  text-decoration: none;
  transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-ghost { background: transparent; color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 18px; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 12px;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ------------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { font-size: 24px; margin: 10px 0 4px; }
.login-card p { margin: 0 0 20px; }
.login-card .field { text-align: left; }

/* ------------------------------------------------------------------ layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; flex: 1; }
.tabs-top { display: none; }

.content {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
}
.tabbar button.on { color: var(--accent); }

@media (min-width: 820px) {
  .tabbar { display: none; }
  .content { padding-bottom: 40px; }
  .tabs-top { display: flex; gap: 4px; }
  .tabs-top button {
    border: 0; background: none; padding: 8px 14px; border-radius: 10px;
    font-weight: 600; color: var(--text-2); cursor: pointer;
  }
  .tabs-top button:hover { background: var(--surface-2); }
  .tabs-top button.on { background: var(--accent-soft); color: var(--accent); }
}

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title { font-size: 17px; font-weight: 700; }
.card > .card-title { margin-bottom: 14px; }

/* ------------------------------------------------------------------ add form */
.when { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; }
.link-btn { border: 0; background: none; padding: 0 2px; color: var(--accent); font-weight: 700; font-size: 14px; cursor: pointer; }

.values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.value-field { display: flex; flex-direction: column; align-items: stretch; gap: 4px; min-width: 0; }
.value-label { font-size: 14px; font-weight: 700; color: var(--text-2); display: flex; flex-direction: column; line-height: 1.15; }
.value-label small { font-weight: 500; color: var(--muted); font-size: 12px; }
.value-field input {
  width: 100%;
  height: 68px;
  padding: 0 4px;
  text-align: center;
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  -moz-appearance: textfield;
}
.value-field input::-webkit-outer-spin-button,
.value-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.value-field input::placeholder { color: var(--border); }
.unit { text-align: center; font-size: 12px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 16px; }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; color: var(--text-2);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.feedback { display: flex; align-items: center; gap: 14px; }
.feedback .big { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.feedback .big small { font-size: 16px; font-weight: 600; }
.feedback .badge { margin-top: 4px; }
.feedback .msg { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.feedback.alert { border-color: var(--critical); }

/* ------------------------------------------------------------------ entries */
.entry-list { display: flex; flex-direction: column; }
.day-head {
  font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  padding: 14px 4px 6px;
}
.day-head:first-child { padding-top: 0; }
.entry {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  grid-template-areas: "time vals badge" "time note note";
  align-items: center; column-gap: 12px;
  padding: 10px 6px;
  border: 0; border-top: 1px solid var(--border);
  background: none; text-align: left; width: 100%; cursor: pointer; border-radius: 0;
}
.entry:hover { background: var(--surface-2); }
.day-head + .entry, .entry:first-child { border-top: 0; }
.entry .t { grid-area: time; font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; }
.entry .v { grid-area: vals; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.entry .v small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.entry .b { grid-area: badge; }
.entry .n { grid-area: note; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-list .empty { padding: 18px 4px; color: var(--muted); text-align: center; }
.entry.static { cursor: default; }
.entry.static:hover { background: none; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  padding: 3px 9px 3px 7px; border-radius: 999px; background: var(--surface-2); white-space: nowrap;
}
.badge::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--dot, var(--muted)); }
.lvl-good { --dot: var(--good); }
.lvl-warning { --dot: var(--warning); }
.lvl-serious { --dot: var(--serious); }
.lvl-critical { --dot: var(--critical); }
.lvl-low { --dot: var(--low); }

/* ------------------------------------------------------------------ history */
.filter-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border-radius: 12px; flex-wrap: wrap;
}
.segmented button {
  border: 0; background: none; padding: 8px 14px; border-radius: 9px;
  font-weight: 600; font-size: 14px; color: var(--text-2); cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .val { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .val small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.stat .s { font-size: 12px; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 16px; height: 0; border-top: 2px solid; border-radius: 2px; }
.sw-sys { border-color: var(--sys); }
.sw-dia { border-color: var(--dia); }
.sw-ref { border-top-style: dashed; border-color: var(--ref); }

.chart { position: relative; width: 100%; height: 240px; touch-action: pan-y; }
.chart-sm { height: 150px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 14px; }

.ax text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.ax line { stroke: var(--grid); stroke-width: 1; }
.refline { stroke: var(--ref); stroke-width: 1.2; stroke-dasharray: 5 4; }
.reflabel { font-size: 11px; fill: var(--muted); }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--surface); stroke-width: 2; }
.endlabel { font-size: 12px; font-weight: 600; fill: var(--text-2); }
.cross { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 2 3; }
.c-sys { stroke: var(--sys); }
.c-dia { stroke: var(--dia); }
.c-pulse { stroke: var(--pulse); }
.f-sys { fill: var(--sys); }
.f-dia { fill: var(--dia); }
.f-pulse { fill: var(--pulse); }
.i-sys { background: var(--sys); }
.i-dia { background: var(--dia); }
.i-pulse { background: var(--pulse); }
.hit { cursor: crosshair; }

.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini-stats .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.mini-stats .val { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 2px 0 6px; }
.mini-stats .val small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.tip { margin: 14px 0 0; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
  padding: 8px 10px; font-size: 13px; min-width: 130px;
}
.tooltip .tt-date { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.tooltip .tt-row b { margin-left: auto; padding-left: 12px; }

/* ------------------------------------------------------------------ dialogs */
dialog.sheet {
  width: calc(100% - 24px); max-width: 520px;
  max-height: calc(100vh - 32px);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 20px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
dialog.sheet h2 { font-size: 20px; margin-bottom: 16px; }
dialog.sheet h3 { font-size: 16px; margin-bottom: 10px; }
.sheet-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.install-box .btn { margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 60;
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  max-width: calc(100% - 32px);
}
@media (min-width: 820px) { .toast { bottom: 24px; } }

/* ------------------------------------------------------------------ report controls */
.report-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
#report-quick { margin-top: 0; }

/* ------------------------------------------------------------------ report paper
   Rapor her zaman açık renkli "kâğıt" olarak görünür (ekranda da, baskıda da). */
.report {
  color-scheme: light;
  --text: #111111;
  --text-2: #3d3c39;
  --muted: #6b6a65;
  --border: #d9d7d1;
  --surface: #ffffff;
  --surface-2: #f3f2ef;
  --grid: #ebe9e4;
  --ref: #8f8e88;
  --sys: #2a78d6;
  --dia: #eb6834;
  --pulse: #1baf7a;
  --low: #4a3aa7;
  background: #ffffff;
  color: var(--text);
  border-radius: 6px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, .12);
  padding: 32px;
  max-width: 794px;
  margin: 0 auto;
  font-size: 13px;
}
@media (max-width: 600px) { .report { padding: 18px 14px; font-size: 12px; } }

.rp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 14px; }
.rp-head h1 { font-size: 20px; }
.rp-head .rp-sub { color: var(--muted); margin-top: 4px; }
.rp-head .rp-meta { text-align: right; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.rp-info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin-bottom: 16px; }
.rp-info dt { font-weight: 700; color: var(--text-2); }
.rp-info dd { margin: 0; }

.rp-section-title { font-size: 14px; font-weight: 700; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }

.rp-summary { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rp-summary th, .rp-summary td { border: 1px solid var(--border); padding: 6px 8px; text-align: center; }
.rp-summary th { background: var(--surface-2); font-weight: 700; }
.rp-summary td:first-child, .rp-summary th:first-child { text-align: left; }

.rp-chart { margin-top: 4px; }
.rp-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.report .legend { margin-bottom: 4px; font-size: 12px; }

.rp-table-wrap { overflow-x: auto; }
.rp-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rp-table th, .rp-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: center; }
.rp-table th { border-bottom: 2px solid #111; font-size: 11px; line-height: 1.25; }
.rp-table th small { font-weight: 500; color: var(--muted); }
.rp-table td.l, .rp-table th.l { text-align: left; }
.rp-table tr.newday td { border-top: 1.5px solid #9a9993; }
.rp-table td.hi { font-weight: 800; }
.rp-table td.hi::after { content: " ▲"; font-size: 9px; }
.rp-table td.note { color: var(--text-2); font-size: 11px; max-width: 220px; }

.rp-foot { margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.rp-empty { padding: 40px 0; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------------ print */
@media print {
  @page { size: A4; margin: 12mm 12mm 14mm; }
  :root { color-scheme: light; }
  html, body { background: #ffffff !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print, .topbar, .tabbar, dialog, .toast, .tooltip, #boot, #login-view { display: none !important; }
  #app-view, #tab-report, #tab-report[hidden] { display: block !important; }
  .tab:not(#tab-report) { display: none !important; }
  .content { padding: 0; max-width: none; }
  .report { box-shadow: none; border-radius: 0; padding: 0; max-width: none; font-size: 11.5px; }
  .rp-table thead { display: table-header-group; }
  .rp-table tr, .rp-summary tr { break-inside: avoid; }
  .rp-chart { break-inside: avoid; }
  .rp-table-wrap { overflow: visible; }
}
