:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e5e7eb;
  --border-strong: #d7dae0;
  --text: #16181d;
  --text-muted: #6b7280;
  --text-faint: #9aa1ac;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --success: #16a34a;
  --success-soft: #eafaf0;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fdeeee;
  --warning: #d97706;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1c1f27;
    --border: #262a34;
    --border-strong: #323744;
    --text: #e8e9ec;
    --text-muted: #9aa1ac;
    --text-faint: #6b7280;
    --accent: #6366f1;
    --accent-hover: #7c7ff2;
    --accent-soft: #1e1f3d;
    --success: #34d399;
    --success-soft: #10281d;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --danger-soft: #2c1618;
    --warning: #fbbf24;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

svg { width: 16px; height: 16px; flex-shrink: 0; vertical-align: -3px; }

h1, h2, h3 { font-weight: 650; letter-spacing: -0.01em; margin: 0 0 4px; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

.app-shell { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  font-weight: 700;
  font-size: 15px;
}
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 15px;
  flex-shrink: 0;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}
.user-chip { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 13px; color: var(--text-muted); }
.user-chip .avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.logout-form { margin-top: 4px; }
.logout-form button {
  width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: 13px; padding: 7px 10px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 8px;
}
.logout-form button:hover { background: var(--surface-2); color: var(--danger); }

/* --- Main content --- */
.main { flex: 1; min-width: 0; }
.page-header {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 32px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-header p.subtitle { color: var(--text-muted); font-size: 13.5px; margin: 4px 0 0; max-width: 60ch; }
.container { max-width: 1080px; margin: 0 auto; padding: 18px 32px 48px; }
.container.wide { max-width: 1280px; }

/* --- Flash messages --- */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}
.flash.success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash svg { width: 16px; height: 16px; flex-shrink: 0; }

/* --- Cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  margin-bottom: 18px;
  overflow-x: auto;
}
.card + .card { margin-top: 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; font-size: 13.5px; }
thead th { color: var(--text-faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
td.actions form, td.actions a.btn, td.actions button.btn { margin-left: 6px; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.12s ease;
  line-height: 1.3;
}
.btn svg { width: 14px; height: 14px; }
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

form.inline { display: inline-block; }

/* --- Forms --- */
input[type=text], input[type=password], input[type=file], input[type=number], select, textarea {
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; }
.form-row .field { flex: 1; margin-bottom: 0; }

/* --- Misc --- */
.breadcrumbs { font-size: 13px; margin-bottom: 16px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.breadcrumbs a { color: var(--text-muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent); }

.muted { color: var(--text-muted); font-size: 13px; }
.faint { color: var(--text-faint); font-size: 12.5px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.telegram { background: #e8f2ff; color: #1c7ed6; border-color: transparent; }
.badge.max { background: #fff1e6; color: #e8590c; border-color: transparent; }
@media (prefers-color-scheme: dark) {
  .badge.telegram { background: #10233b; color: #6cb2f4; }
  .badge.max { background: #3a2412; color: #f0975a; }
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-faint);
  font-size: 13.5px;
}
.empty-state svg { width: 32px; height: 32px; margin-bottom: 10px; opacity: 0.5; }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px 16px;
}
.checkbox-grid label {
  font-size: 13.5px; font-weight: 400;
  display: flex; gap: 8px; align-items: center;
  padding: 4px 0;
}
.checkbox-grid input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

.entry-icon { opacity: 0.7; margin-right: 2px; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card { width: 340px; }
.login-card .logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 20px; margin: 0 auto 16px;
}
.login-card h2 { text-align: center; margin-bottom: 4px; }
.login-card p.subtitle { text-align: center; margin: 0 0 20px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a {
  padding: 9px 14px; font-size: 13.5px; font-weight: 500;
  color: var(--text-muted); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* --- Mobile --- */
.mobile-topbar { display: none; }

@media (max-width: 768px) {
  .app-shell { display: block; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
  }
  .mobile-topbar .menu-btn {
    background: none; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    color: var(--text); cursor: pointer; flex-shrink: 0;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0,0,0,0.4); }
  .page-header { padding: 18px 16px 0; flex-direction: column; }
  .container { padding: 16px 16px 40px; }
  .form-row { flex-direction: column; align-items: stretch; }
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
}
