:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e8e3dc;
  --text: #2a2622;
  --muted: #7a7168;
  --accent: #c8553d;
  --accent-2: #e9a23b;
  --accent-soft: #fbeae5;
  --ok: #2f8f5b;
  --ok-soft: #e4f4ea;
  --warn: #a8670a;
  --warn-soft: #fdf1dc;
  --err: #c0392b;
  --err-soft: #fbe5e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(42, 38, 34, .06), 0 4px 16px rgba(42, 38, 34, .05);
  --sidebar: 236px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
small, .muted { color: var(--muted); }

/* --- layout --- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: #2a2622; color: #efe9e2;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 18px 12px; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 15px; color: #fff; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; font-size: 18px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: #d9d1c7; font-weight: 500;
  text-decoration: none; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav .ico { width: 20px; text-align: center; }
.nav .badge { margin-left: auto; background: var(--accent-2); color: #2a2622; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8f857a; padding: 14px 12px 6px; }
.sidebar .spacer { flex: 1; }
.sidebar form button { width: 100%; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-bar { display: none; }

/* --- components --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.kpi { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.form-side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.kpi .card { padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi .sub b { color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
  white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--err); border-color: #f0c9c3; }
.btn.danger:hover { background: var(--err-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.dark { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.1); color: #d9d1c7; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.error { background: var(--err-soft); color: var(--err); }

/* --- forms --- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text);
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 90px; resize: vertical; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; margin: 0 14px 6px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 180px; }

.ing-table { min-width: 860px; }
.ing-table td { padding: 6px 5px; border: none; }
.ing-table tr td { border-top: 1px dashed var(--border); }
.ing-table input, .ing-table select { padding: 7px 8px; font-size: 13px; }
.ing-table .col-ing { min-width: 200px; }
.ing-table .col-note { min-width: 170px; }
.ing-table .col-section { width: 130px; }
.ing-table .col-amount { width: 82px; }
.ing-table .col-unit { width: 120px; }
.ing-table .col-opt { width: 40px; text-align: center; }
.ing-table .col-act { width: 92px; white-space: nowrap; }

/* --- telegram preview --- */
.tg-preview { background: #d7e6d1 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='1.2' fill='%23b7cdb0'/%3E%3C/svg%3E"); border-radius: var(--radius); padding: 14px; max-height: 80vh; overflow-y: auto; }
.tg-bubble { background: #fff; color: #000; border-radius: 12px 12px 12px 4px; padding: 9px 12px; white-space: pre-wrap; font-size: 13.5px; line-height: 1.45; box-shadow: 0 1px 1px rgba(0,0,0,.1); word-wrap: break-word; }
.tg-bubble i { color: #333; }
.sticky { position: sticky; top: 16px; }

/* --- chart --- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.chart .bar { flex: 1; background: var(--accent-soft); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.chart .bar span { position: absolute; inset: auto 0 0 0; background: var(--accent); border-radius: 4px 4px 0 0; }
.chart .bar:hover span { background: var(--accent-2); }
.chart-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.list-rows .r { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.list-rows .r:last-child { border-bottom: none; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.meter span { display: block; height: 100%; background: var(--accent-2); }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* --- login --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #fbeae5, transparent 50%), radial-gradient(circle at 80% 90%, #fdf1dc, transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--text); justify-content: center; padding-bottom: 6px; font-size: 18px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171513; --surface: #201d1a; --surface-2: #26221f; --border: #35302b; --text: #efe9e2; --muted: #a39a90;
    --accent-soft: #3a2420; --ok-soft: #1c3326; --warn-soft: #3a2c14; --err-soft: #3b1f1b;
    --shadow: none;
  }
  .sidebar { background: #110f0e; }
  .tg-preview { background-color: #1d2a22; }
  .login-wrap { background: var(--bg); }
}

@media (max-width: 1250px) {
  .grid.form-side { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
}
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: #2a2622; color: #fff; position: sticky; top: 0; z-index: 20; }
  .mobile-bar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 18px 16px 50px; }
  .kpi .value { font-size: 22px; }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
  .hide-sm { display: none; }
}
