[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --ink: #161a23;
  --muted: #6b7280;
  --soft: #eef1f5;
  --surface: #ffffff;
  --line: #e3e7ee;
  --accent: #16a673;
  --accent-dark: #0e7a55;
  --accent-soft: #e3f6ee;
  --blue: #2563eb;
  --blue-soft: #e7eefd;
  --amber: #b8740f;
  --amber-soft: #fbeed9;
  --red: #dc3a3a;
  --red-soft: #fbe6e5;
  --sidebar-bg: #0f1620;
  --sidebar-ink: #e8edf1;
  --sidebar-muted: #8a97a6;
  --shadow-sm: 0 2px 8px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 10px 28px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

a,
label,
button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  flex-shrink: 0;
}

.svg-sprite {
  display: none;
}

/* Login */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.login-screen::before,
.login-screen::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  z-index: 0;
}

.login-screen::before {
  width: 480px;
  height: 480px;
  top: -160px;
  left: -120px;
  background: radial-gradient(circle, rgba(22, 166, 115, 0.35), transparent 70%);
}

.login-screen::after {
  width: 420px;
  height: 420px;
  bottom: -180px;
  right: -120px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.25), transparent 70%);
}

.login-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}

.login-logo {
  width: 52px;
  height: 52px;
  display: block;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

h1,
h2,
h3,
h4,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0 0 26px;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.25;
}

h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

.login-form label,
.field label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--soft);
  color: var(--ink);
  padding: 10px 13px;
  outline: none;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease), background 140ms var(--ease);
}

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

input:focus,
select:focus,
textarea:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-error {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 0.88rem;
  font-weight: 600;
}

.login-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Shell */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  transition: grid-template-columns 200ms var(--ease);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 80px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 22px 16px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
}

.sidebar-head {
  display: grid;
  grid-template-columns: 1fr 40px;
  align-items: center;
  gap: 8px;
}

.brand {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand img {
  width: 40px;
  height: 40px;
}

.brand strong {
  display: block;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand span {
  display: block;
  color: var(--sidebar-muted);
  font-size: 0.8rem;
}

.sidebar-toggle {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-ink);
}

.app-shell.sidebar-collapsed .sidebar {
  padding-inline: 12px;
}

.app-shell.sidebar-collapsed .sidebar-head {
  grid-template-columns: 1fr;
}

.app-shell.sidebar-collapsed .brand {
  grid-template-columns: 40px;
  justify-content: center;
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .nav-button span {
  display: none;
}

.app-shell.sidebar-collapsed .nav-button {
  grid-template-columns: 1fr;
  place-items: center;
  padding-inline: 0;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  width: 100%;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-button {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-muted);
  padding: 10px 12px;
  text-align: left;
  text-decoration: none;
  font-weight: 600;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}

.nav-button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-ink);
}

.nav-button.active {
  background: rgba(22, 166, 115, 0.18);
  color: #fff;
  border-color: rgba(22, 166, 115, 0.4);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 28px;
  background: rgba(243, 245, 247, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.btn {
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
  white-space: nowrap;
  font-weight: 600;
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease), background 140ms var(--ease), border-color 140ms var(--ease);
}

.icon-btn {
  position: relative;
  width: 42px;
  padding: 0;
}

.btn {
  padding: 9px 14px;
  font-weight: 700;
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 8px 18px rgba(14, 122, 85, 0.28);
}

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

.btn.ghost {
  background: transparent;
}

.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.badge {
  position: absolute;
  top: 7px;
  right: 7px;
  min-width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--red);
  border: 2px solid var(--surface);
}

.content {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 24px 28px 42px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.45fr);
  gap: 16px;
  align-items: stretch;
}

.chart-panel {
  min-height: 290px;
}

.bar-chart {
  height: 210px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
  padding-top: 14px;
}

.bar {
  min-width: 0;
  display: grid;
  align-items: end;
  gap: 8px;
}

.bar span {
  display: block;
  min-height: 12px;
  border-radius: 7px 7px 2px 2px;
  background: linear-gradient(180deg, var(--accent), var(--blue));
}

.bar small {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.analytics-list {
  display: grid;
  gap: 14px;
}

.analytics-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.analytics-row p {
  margin: 0;
}

.analytics-row strong {
  font-size: 1.05rem;
}

.mini-progress {
  grid-column: 1 / -1;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft);
}

.mini-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.mini-progress span.siberian {
  background: var(--amber);
}

.mini-progress span.lawyer {
  background: var(--blue);
}

.mini-progress span.alert {
  background: var(--red);
}

.toggle-list {
  display: grid;
  gap: 10px;
}

.toggle-row {
  min-height: 48px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--soft);
}

.toggle-row p {
  margin: 0;
}

.toggle-row input {
  width: 44px;
  min-height: 24px;
  accent-color: var(--accent);
}

.section-grid {
  display: grid;
  gap: 16px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
  align-items: start;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.card,
.panel,
.module-card,
.metric,
.notification-item,
.timeline-item,
.order-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card,
.panel {
  padding: 20px;
}

.metric {
  min-height: 118px;
  padding: 17px;
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
}

.metric:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric .value {
  margin: 10px 0 4px;
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.metric .label,
.metric .caption {
  margin: 0;
  color: var(--muted);
  font-size: 0.87rem;
}

.metric.memory {
  border-left: 4px solid var(--accent);
}

.metric.siberian {
  border-left: 4px solid var(--amber);
}

.metric.lawyer {
  border-left: 4px solid var(--blue);
}

.metric.alert {
  border-left: 4px solid var(--red);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.module-card {
  min-height: 190px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
}

.module-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.module-card header {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
}

.module-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.module-icon.memory {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.module-icon.siberian {
  background: var(--amber-soft);
  color: var(--amber);
}

.module-icon.lawyer {
  background: var(--blue-soft);
  color: var(--blue);
}

.module-card p {
  margin: 0;
  color: var(--muted);
}

.module-card .btn {
  margin-top: auto;
  width: fit-content;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 0.38fr);
  gap: 16px;
  align-items: start;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field.full {
  grid-column: 1 / -1;
}

.status-row,
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--soft);
  white-space: nowrap;
}

.status.ok {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status.wait {
  background: var(--amber-soft);
  color: #815012;
}

.status.info {
  background: var(--blue-soft);
  color: #1d4ed8;
}

.status.danger {
  background: var(--red-soft);
  color: #b42a2a;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
}

th {
  background: var(--soft);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  transition: background 120ms var(--ease);
}

tbody tr:hover {
  background: var(--soft);
}

.notification-list,
.timeline {
  display: grid;
  gap: 10px;
}

.notification-item,
.timeline-item {
  padding: 13px;
}

.notification-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
}

.dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--accent);
}

.dot.amber {
  background: var(--amber);
}

.dot.blue {
  background: var(--blue);
}

.dot.red {
  background: var(--red);
}

.notification-item p,
.timeline-item p,
.order-card p {
  margin: 0;
}

.notification-meta,
.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 10;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 50px rgba(16, 24, 40, 0.16);
}

.drawer[hidden] {
  display: none;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.order-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.order-card {
  display: grid;
  gap: 10px;
  padding: 15px;
}

.progress {
  height: 8px;
  overflow: hidden;
  background: var(--soft);
  border-radius: 999px;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
}

.file-input {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1.5px dashed #c4cbd4;
  border-radius: var(--radius);
  background: var(--soft);
}

.template-preview {
  min-height: 220px;
  white-space: pre-wrap;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: #1f2430;
  font-size: 0.92rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  max-width: min(520px, calc(100% - 32px));
  min-height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--sidebar-bg);
  color: #fff;
  padding: 10px 16px;
  font-weight: 600;
  transform: translateX(-50%);
  box-shadow: var(--shadow-lg);
}

.toast.show {
  display: flex;
}

@media (max-width: 1180px) {
  .dashboard-grid,
  .split-grid,
  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .kpi-grid,
  .module-grid,
  .order-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Mobile sidebar backdrop */
.mob-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  cursor: pointer;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

/* Hamburger visible only on mobile */
.mob-menu-btn {
  display: none;
}

/* Badge utility */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

@media (max-width: 820px) {
  /* Sidebar becomes fixed overlay drawer */
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(288px, 88vw);
    height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(0.2, 0.6, 0.2, 1);
    overflow-y: auto;
    padding: 16px;
    gap: 16px;
    box-shadow: none;
    overscroll-behavior: contain;
  }

  .sidebar.mob-open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0, 0, 0, 0.36);
  }

  .mob-backdrop.mob-open {
    display: block;
  }

  /* Safe area for sidebar top (iPhone notch) */
  .sidebar-head {
    grid-template-columns: 1fr auto;
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* Hide desktop sidebar toggle, show hamburger */
  .sidebar-toggle {
    display: none;
  }

  .mob-menu-btn {
    display: flex;
  }

  /* Always-expanded brand & nav in mobile drawer */
  .app-shell.sidebar-collapsed .brand-copy,
  .app-shell.sidebar-collapsed .nav-button span {
    display: initial;
  }

  .app-shell.sidebar-collapsed .brand {
    grid-template-columns: 36px 1fr;
  }

  .app-shell.sidebar-collapsed .nav-button {
    grid-template-columns: 20px minmax(0, 1fr);
    place-items: initial;
    padding: 9px 10px;
  }

  .brand {
    grid-template-columns: 36px 1fr;
  }

  .brand img {
    width: 36px;
    height: 36px;
  }

  .nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .nav-button {
    width: 100%;
    min-width: 0;
    grid-template-columns: 20px minmax(0, 1fr);
    padding: 12px 10px;
  }

  /* Topbar: safe area + hamburger space */
  .topbar {
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    min-height: 56px;
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 10px;
  }

  .topbar > div:first-child {
    flex: 1;
    min-width: 0;
  }

  .content {
    padding: 14px 12px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .kpi-grid,
  .module-grid,
  .order-grid,
  .two-col,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .password-row {
    grid-template-columns: 1fr;
  }

  .login-panel {
    padding: 26px 22px;
  }

  h1 {
    font-size: 1.7rem;
  }

  h2 {
    font-size: 1.18rem;
  }

  .btn {
    width: 100%;
    min-height: 46px;
  }

  .toolbar .btn,
  .toolbar-actions .btn,
  .drawer-actions .btn,
  .module-card .btn,
  .password-row .btn {
    width: auto;
    min-height: 40px;
  }

  /* Panel / toolbar responsive */
  .toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  /* Table scroll */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 560px;
  }
}

@media (max-width: 480px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-shrink: 0;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-actions,
  .toolbar-actions .btn {
    width: 100%;
  }

  .toolbar-actions .btn {
    justify-content: center;
  }

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

  table {
    min-width: 680px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .login-panel {
    padding: 20px 16px;
  }
}
