:root,
html[data-theme="light"] {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --line: #d7e0da;
  --text: #14201c;
  --muted: #5d6d66;
  --accent: #3f9b2a;
  --accent-soft: #e5f6dc;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(20, 32, 28, 0.06);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0e1311;
  --panel: #161c19;
  --sidebar: #121815;
  --line: #2a3530;
  --text: #eef5ef;
  --muted: #9aaba0;
  --accent: #63c52f;
  --accent-soft: #1c2c1d;
  --danger: #ff8f7a;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; }
.auth-body { display: grid; place-items: center; padding: 28px 16px; }
.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card .brand { color: var(--accent); font-size: 12px; letter-spacing: 0.14em; font-weight: 800; }
.auth-card h1 { margin: 10px 0 8px; font-size: 28px; font-weight: 600; }
.auth-card p { color: var(--muted); line-height: 1.55; }
.auth-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px;
}
.sidebar-brand .mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: block;
  flex-shrink: 0;
  object-fit: contain;
  background: #090c12;
}
.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  line-height: 1.15;
}
.sidebar-brand strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
}
.sidebar-brand small {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sidebar-nav a {
  color: var(--text);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}
.sidebar-nav a:hover { background: var(--accent-soft); }
.sidebar-nav a.active { background: var(--accent); color: #13210d; }
html[data-theme="dark"] .sidebar-nav a.active { color: #14200d; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
.theme-toggle {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.theme-toggle .theme-icon { display: none; line-height: 0; }
html[data-theme="light"] .theme-toggle .theme-icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }

.account-menu { position: relative; }
.avatar-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.avatar-btn:hover,
.account-menu.open .avatar-btn {
  border-color: var(--accent);
}
.avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.account-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(240px, 78vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 30;
}
.account-meta {
  display: grid;
  gap: 6px;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.account-meta strong {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.role-pill {
  display: inline-flex;
  width: fit-content;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.logout-form { margin: 0; }
.logout-form button { width: 100%; }
.content { padding: 24px 28px 48px; width: min(1100px, 100%); }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 8px; font-size: 18px; }
.panel > p { color: var(--muted); margin: 0 0 16px; }

label { display: block; font-size: 12px; margin: 12px 0 6px; color: var(--muted); font-weight: 700; }
input, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
button, .button {
  border: 0;
  border-radius: 9px;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #13210d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.ghost, .button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
button.danger { background: var(--danger); color: #fff; }
button:disabled, .button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.menu-btn { display: none; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 96px;
}
.note-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--bg);
}
.note-card p { margin: 8px 0 0; white-space: pre-wrap; }
.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--bg);
}
.stat span { color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 8px; font-size: 24px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge.off { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.flash { padding: 11px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; }
.flash.ok { background: var(--accent-soft); color: var(--accent); }
.flash.err { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
ul.check { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.7; }
.filters { margin-top: 8px; }
.muted-line { color: var(--muted); font-size: 12px; margin-top: 4px; }
.message-cell {
  max-width: 280px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  color: var(--muted);
}
.status-form { margin: 0; }
.status-form select {
  min-width: 120px;
  padding: 8px 10px;
  font-size: 13px;
}
.inline-form { display: grid; gap: 8px; min-width: 180px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw); z-index: 20;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .row, .grid { grid-template-columns: 1fr; }
  .content, .topbar { padding-inline: 16px; }
  .theme-toggle, .avatar-btn { width: 38px; height: 38px; }
  .avatar-circle { width: 30px; height: 30px; font-size: 11px; }
}
