/* Светлая тема по умолчанию */
:root {
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #e2e8f0;
  --border: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  --font: "Manrope", -apple-system, system-ui, sans-serif;
  --hover-overlay: rgba(0, 0, 0, 0.05);
  --shadow-card: 0 12px 40px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-sidebar: #0d1218;
  --border: #2d3a4d;
  --text: #e8eaed;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --hover-overlay: rgba(255, 255, 255, 0.06);
  --shadow-card: 0 16px 48px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Login */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: linear-gradient(145deg, #e2e8f0 0%, #f1f5f9 45%, #f8fafc 100%);
}

[data-theme="dark"] #login-screen {
  background: linear-gradient(145deg, #0a0e14 0%, #151d2b 45%, #0f1419 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-card);
}

.login-title {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.login-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-form label {
  display: block;
  margin-bottom: 1rem;
}

.login-form label span {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.login-form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.error-msg {
  color: #f87171;
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
  min-height: 1.25rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 0.7rem 1rem;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: #b91c1c;
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  width: 100%;
  justify-content: flex-start;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--hover-overlay);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* App shell */
#app-screen {
  display: flex;
  min-height: 100vh;
}

#login-screen.hidden {
  display: none;
}

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.15rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 700;
  font-size: 1.15rem;
  display: block;
}

.user-role {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-impersonate {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 8px;
  font-size: 0.8rem;
}

.sidebar-impersonate label {
  display: block;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.sidebar-impersonate select {
  width: 100%;
  padding: 0.45rem 0.5rem;
  font-size: 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
}

.sidebar-impersonate .imp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.sidebar-impersonate .imp-actions .btn {
  width: auto;
  flex: 1;
  min-width: 0;
  justify-content: center;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.65rem 0;
  overflow-y: auto;
  min-height: 0;
}

.nav-link {
  display: block;
  padding: 0.65rem 1.15rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--hover-overlay);
}

.nav-link.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(59, 130, 246, 0.12);
}

.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--bg-card);
}

.main-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.user-info {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 100%;
  word-break: break-word;
}

.page-content {
  flex: 1;
  padding: 1.25rem;
  overflow: auto;
}

.content-section {
  max-width: 1100px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.card h3 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

label {
  display: block;
  margin: 0.5rem 0 0.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

input,
textarea,
select {
  font: inherit;
  width: 100%;
  max-width: 520px;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.ok {
  color: var(--success);
  font-weight: 500;
}

.error {
  color: #f87171;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.form-actions .btn {
  width: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}

/* Mobile sidebar */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--hover-overlay);
}

.sidebar-toggle-icon {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

@media (max-width: 900px) {
  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar-overlay {
    display: block;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  #app-screen.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 88vw);
    z-index: 101;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }

  #app-screen.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }

  .page-content {
    padding: 1rem;
  }

  .main-header {
    padding: 0.65rem 1rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  input,
  textarea,
  select {
    max-width: none;
  }
}
