:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202b;
  --muted: #5d6877;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --warn-bg: #fff6e0;
  --warn-text: #7a5300;
  --ok: #1d7a46;
  --empty: #eef1f5;
  --selected: #2563eb;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --surface: #1a2029; --surface-2: #222a35; --text: #e6eaf0; --muted: #9aa5b4;
    --border: #2f3a48; --accent: #5b8def; --danger: #ef6b6b; --warn-bg: #3a2f12; --warn-text: #f3d48a;
    --ok: #4cc37f; --empty: #232b36; --selected: #7aa5ff; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
#nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
#nav a.primary-link { color: var(--accent); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; gap: 12px; align-items: center; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 6px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* formlar */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.field { display: grid; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field .req::after { content: " *"; color: var(--danger); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { min-height: 60px; resize: vertical; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg label { padding: 6px 12px; cursor: pointer; font-size: 0.9rem; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.hint { font-size: 0.82rem; color: var(--muted); }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 6px; padding: 8px 12px; font-size: 0.9rem; }
.error { color: var(--danger); font-weight: 600; }

/* tank haritası */
.tank { display: grid; grid-template-columns: 34px repeat(4, minmax(0, 1fr)); gap: 8px; }
.tank .th { font-weight: 700; text-align: center; color: var(--muted); align-self: center; }
.box-tile { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; }
.box-tile:hover { border-color: var(--accent); }
.box-tile .tile-head { display: flex; justify-content: space-between; font-size: 0.85rem; }
.box-tile .tile-head b { font-size: 0.95rem; }
.mini { width: 100%; max-width: 132px; margin: 0 auto; display: grid; grid-template-columns: repeat(9, 1fr); gap: 1px; }
.mini i { aspect-ratio: 1; border-radius: 1px; background: var(--empty); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.4rem; }

/* 9x9 kutu */
.box-layout { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 20px; align-items: start; }
.box { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.slot { aspect-ratio: 1; border-radius: 6px; border: 1px solid transparent; background: var(--empty); color: var(--muted); font-size: 0.72rem; display: flex; flex-direction: column; justify-content: space-between; padding: 3px 4px; cursor: pointer; text-align: left; overflow: hidden; font-family: inherit; }
.slot .num { font-size: 0.68rem; opacity: 0.8; }
.slot .nm { font-weight: 700; font-size: 0.72rem; line-height: 1.05; color: #111; word-break: break-all; }
.slot .ps { font-size: 0.65rem; color: #222; }
.slot.full { color: #111; }
.slot.full .num { color: #222; }
.slot:hover { border-color: var(--text); }
.slot.sel { outline: 3px solid var(--selected); outline-offset: -1px; }
.slot.ghost { background: repeating-linear-gradient(45deg, var(--empty), var(--empty) 4px, color-mix(in srgb, var(--accent) 25%, var(--empty)) 4px, color-mix(in srgb, var(--accent) 25%, var(--empty)) 8px); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; }
.legend span::before { content: ""; display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: var(--c); margin-right: 5px; vertical-align: -1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; }

/* tablolar */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; color: var(--muted); font-size: 0.75rem; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.wrap { white-space: normal; min-width: 200px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; background: var(--surface-2); border: 1px solid var(--border); }
.badge.ok { color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge.bad { color: var(--danger); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* diyalog & toast */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 16px 18px; display: grid; gap: 14px; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 0.88rem; }
dl.kv dd { margin: 0; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
.logged-out #nav, .logged-out .topbar-right { display: none; }
.login { max-width: 400px; margin: 40px auto; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }

@media (max-width: 820px) {
  .box-layout { grid-template-columns: 1fr; }
  .tank { grid-template-columns: 24px repeat(4, minmax(0, 1fr)); gap: 4px; }
  .box-tile { padding: 4px; }
  .box-tile .tile-head span { display: none; }
  .slot .nm, .slot .ps { display: none; }
  dl.kv { grid-template-columns: 110px 1fr; }
  .topbar { padding: 8px 16px; }
}

@media print {
  .topbar, .no-print, #toast { display: none !important; }
  body { background: white; color: black; }
  main { padding: 0; max-width: none; }
  .box-layout { grid-template-columns: 1fr; }
  .box { border: none; width: 18cm; }
  .slot { border: 1px solid #999 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .slot .nm, .slot .ps { display: block; }
}
