:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2230;
  --muted: #667085;
  --primary: #1f6f5c;
  --primary-hover: #185a4a;
  --primary-soft: #e3f1ec;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #9a6400;
  --warn-soft: #fff4d6;
  --ok: #1f6f5c;
  --ok-soft: #e3f1ec;
  --folder: #d99a1e;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #222733;
    --border: #2e3442;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --primary: #3fae8f;
    --primary-hover: #52c2a2;
    --primary-soft: #18352d;
    --danger: #f07167;
    --danger-soft: #3a1f1d;
    --warn: #f2c14e;
    --warn-soft: #3a3019;
    --ok: #52c2a2;
    --ok-soft: #18352d;
    --folder: #f2b640;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
h3 { font-size: 17px; font-weight: 600; }
ul { margin: 0; padding-left: 18px; }
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; }
.title-icon { width: 24px; height: 24px; color: var(--muted); }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Üst bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .icon { color: var(--primary); width: 22px; height: 22px; }
.search {
  flex: 1; max-width: 480px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.search .icon { color: var(--muted); width: 16px; }
.search input { border: 0; background: transparent; padding: 8px 0; width: 100%; outline: none; box-shadow: none; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox form { margin: 0; }
.username { font-weight: 500; }

.page { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }

/* Butonlar */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; min-height: 36px;
  font: inherit; font-weight: 500; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; white-space: nowrap; list-style: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; min-height: 30px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
/* Buton içeren formlar (Kopyala, Sil) diğer butonlarla aynı sırada dizilsin. */
.actions form { display: contents; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  color: var(--muted); background: transparent; border: 0; border-radius: 6px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .icon { width: 16px; height: 16px; }

/* Form alanları */
input, select {
  font: inherit; color: var(--text);
  width: 100%; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
label > span { display: block; font-weight: 500; margin-bottom: 4px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* Bildirimler */
.flash {
  padding: 10px 14px; margin-bottom: 16px; border-radius: 8px;
  border: 1px solid transparent; transition: opacity .4s;
}
.flash.success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash.fade { opacity: 0; }

/* Sayfa başlığı */
.page-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; min-height: 30px; }
.page-top:empty { display: none; }
.back-btn { flex: none; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-width: 0; color: var(--muted); font-size: 13px; }
.breadcrumb a { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.breadcrumb .icon { width: 15px; height: 15px; }
.breadcrumb .sep { width: 13px; height: 13px; opacity: .6; }
.breadcrumb .current { color: var(--text); font-weight: 500; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 10px; }

/* Kartlar */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }

.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.folder-card {
  display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center;
  padding: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.folder-card:hover { border-color: var(--primary); text-decoration: none; }
.folder-icon { grid-row: span 2; width: 30px; height: 30px; color: var(--folder); fill: color-mix(in srgb, var(--folder) 18%, transparent); }
.folder-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-meta { font-size: 12px; color: var(--muted); }

/* Tablolar */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap, .table-wrap.card { border: 0; box-shadow: none; border-radius: 0; }
.table-wrap.card { border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  padding: 10px 12px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
table.data th.num { text-align: right; }
table.data th.center { text-align: center; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
td.idx, th.idx { width: 40px; color: var(--muted); text-align: center; }
td.clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.row-actions { white-space: nowrap; text-align: right; width: 1%; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* Formül editörü */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: span 2; }
.editor td { padding: 6px 8px; }
.editor input { padding: 6px 8px; }
.editor .col-ratio { width: 120px; }
.editor .col-amount { width: 130px; }
.editor td.amount { font-weight: 600; }
.suffix-input { position: relative; }
.suffix-input input { padding-right: 26px; text-align: right; }
.suffix-input span { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.editor-foot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--border); }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* Hammadde grupları */
.group-card { margin-bottom: 12px; }
.group-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--primary-soft);
  border-bottom: 1px solid var(--border);
}
.group-icon { color: var(--primary); }
.group-name { flex: 1 1 220px; max-width: 360px; font-weight: 600; }
.group-sum { font-size: 13px; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.group-tools { display: flex; gap: 2px; margin-left: auto; }
.group-tools .group-remove:hover { color: var(--danger); }
.analyses-card { margin-top: 4px; }
.analyses-title { font-size: 15px; font-weight: 600; margin: 0; }
.editor .col-analysis { width: 40%; }
table.data th.analysis-name { width: 40%; font-size: 14px; font-weight: 600; color: var(--text); background: transparent; border-bottom: 1px solid var(--border); }
table.data tbody tr:last-child th.analysis-name { border-bottom: 0; }
.groups-foot { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }

table.grouped .group-title th {
  padding: 9px 12px; font-size: 14px; color: var(--text);
  background: var(--primary-soft); border-top: 1px solid var(--border);
}
table.grouped .group-title th .icon { width: 16px; height: 16px; color: var(--primary); vertical-align: -3px; margin-right: 6px; }
table.grouped tbody:first-of-type .group-head th { border-top: 0; }
table.grouped tbody tr.group-total td {
  font-weight: 600; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
table.grouped tbody tr.group-total:hover td { background: var(--surface-2); }

.summary { display: flex; flex-wrap: wrap; gap: 12px 40px; align-items: center; }
.stat { display: flex; flex-direction: column; }
.stat strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-warning { margin: 0 0 0 auto; padding: 6px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-weight: 500; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.info-grid > div { display: flex; flex-direction: column; min-width: 0; }
.info-grid .wide { grid-column: span 2; }

/* Boş durum */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state h1 { justify-content: center; }
.empty-state.small { padding: 36px 20px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.card .empty-state.small { border: 0; }
.empty-state p { color: var(--muted); margin: 8px 0 16px; }
.empty-icon { width: 36px; height: 36px; color: var(--muted); }

/* Dialog */
dialog {
  width: min(420px, calc(100vw - 32px)); padding: 20px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 20px 50px rgb(16 24 40 / 25%);
}
dialog::backdrop { background: rgb(16 24 40 / 45%); }
dialog p { margin: -8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Giriş / kayıt */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(400px, 100%); padding: 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 18px; }
.auth-card > p.muted { margin: 6px 0 20px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.auth-brand .icon { color: var(--primary); width: 26px; height: 26px; }
.auth-switch { text-align: center; margin: 18px 0 0; color: var(--muted); }
.auth-page > .flash { width: min(400px, 100%); }

/* Mobil alt gezinme çubuğu */
.mobile-nav { display: none; }

@media (max-width: 720px) {
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .username, .hide-sm { display: none; }
  .userbox { margin-left: auto; }
  .page { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .form-grid .wide, .info-grid .wide { grid-column: auto; }
  .stat-warning { margin-left: 0; }

  .page-head > div { flex-basis: 100%; }
  .back-btn span { display: none; }
  .back-btn { padding: 5px 8px; }
  .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .actions .btn { width: 100%; min-height: 42px; }
  .actions .btn span { overflow: hidden; text-overflow: ellipsis; }

  .mobile-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgb(16 24 40 / 8%);
  }
  .mobile-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 4px; border-radius: 8px;
    font-size: 11px; font-weight: 500; color: var(--muted);
  }
  .mobile-nav a:hover { text-decoration: none; background: var(--surface-2); }
  .mobile-nav a.active { color: var(--primary); }
  .mobile-nav .icon { width: 22px; height: 22px; }
}
