:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #171a21;
  --muted: #687083;
  --line: #e4e7ec;
  --accent: #4f46e5;
  --accent-dark: #3730a3;
  --positive: #087a55;
  --negative: #b42318;
  --warning: #9a6700;
  --sidebar: #171c27;
  --sidebar-muted: #aeb6c5;
  --radius: 12px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; color: var(--text); background: var(--bg); font-size: 15px; }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; color: #fff; background: var(--sidebar); z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 24px; font-weight: 700; }
.brand-mark { width: 36px; height: 36px; display: inline-grid; place-items: center; flex: 0 0 auto; border-radius: 10px; color: #fff; background: var(--accent); }
.nav-list { display: grid; gap: 5px; }
.nav-link { min-height: 43px; display: flex; align-items: center; gap: 10px; padding: 0 11px; border-radius: 9px; color: var(--sidebar-muted); }
.nav-link:hover, .nav-link.is-active { color: #fff; background: rgba(99, 102, 241, .25); }
.nav-icon { width: 22px; text-align: center; font-size: 18px; }
.sidebar-user { margin-top: auto; padding: 16px 10px 2px; border-top: 1px solid rgba(255,255,255,.12); display: grid; gap: 5px; }
.sidebar-user span { color: var(--sidebar-muted); font-size: 13px; }
.text-button { border: 0; padding: 3px 0; color: #c7d2fe; background: transparent; cursor: pointer; }
.main-column { min-width: 0; }
.mobile-header { display: none; min-height: 58px; align-items: center; gap: 12px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.content { width: min(1440px, 100%); margin: 0 auto; padding: 28px 30px 42px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-header h1 { margin: 0 0 5px; font-size: 28px; line-height: 1.2; }
.page-header p { margin: 0; color: var(--muted); }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin-bottom: 17px; }
.stat { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-value { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-note { margin-top: 6px; color: var(--muted); font-size: 12px; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

.panel { margin-bottom: 17px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 18px; }
.panel-body { padding: 18px; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); background: var(--panel-soft); font-size: 13px; font-weight: 650; }
td { font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.cell-main { font-weight: 650; }
.cell-sub { margin-top: 3px; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.total-row td { background: var(--panel-soft); font-weight: 700; }

.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 999px; background: #eef2ff; color: var(--accent-dark); font-size: 12px; }
.badge-active, .badge-completed { color: var(--positive); background: #ecfdf3; }
.badge-frozen, .badge-rejected { color: var(--negative); background: #fef3f2; }
.badge-disabled, .badge-pending { color: var(--warning); background: #fffaeb; }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 14px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel); cursor: pointer; }
.button:hover { background: var(--panel-soft); }
.button-primary { color: #fff; border-color: var(--accent); background: var(--accent); }
.button-primary:hover { background: var(--accent-dark); }
.button-danger { color: var(--negative); }
.button-small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.button-block { width: 100%; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { min-width: 0; display: grid; gap: 7px; }
.field > span { font-weight: 650; font-size: 14px; }
.field small { color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; color: var(--text); background: #fff; border: 1px solid #cdd2da; border-radius: 8px; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(79, 70, 229, .14); border-color: var(--accent); }
.form-actions { display: flex; flex-wrap: wrap; gap: 9px; padding-top: 4px; }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.inline-form .field { min-width: 150px; }

.alert { margin-bottom: 16px; padding: 12px 14px; border-radius: 9px; border: 1px solid transparent; }
.alert-success { color: #05603a; background: #ecfdf3; border-color: #abefc6; }
.alert-error { color: #912018; background: #fef3f2; border-color: #fecdca; }
.alert-warning { color: #7a2e0e; background: #fffaeb; border-color: #fedf89; }
.secret-alert { word-break: break-all; user-select: all; }
.empty-state { padding: 50px 22px; text-align: center; color: var(--muted); }
.pagination { display: flex; justify-content: flex-end; gap: 6px; padding: 14px 16px; border-top: 1px solid var(--line); }
.help-text { color: var(--muted); line-height: 1.7; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 15% 10%, #e0e7ff, transparent 35%), var(--bg); }
.login-panel { width: min(420px, 100%); padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 55px rgba(35, 43, 62, .12); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand h1 { margin: 0 0 4px; font-size: 23px; }
.login-brand p { margin: 0; color: var(--muted); }

@media (max-width: 1050px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 230px; transform: translateX(-102%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.25); }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .content { padding: 20px 14px 32px; }
  .page-header { display: grid; }
  .header-actions { justify-content: flex-start; }
  .page-header h1 { font-size: 24px; }
  .form-grid, .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .stat-value { font-size: 22px; }
  .login-panel { padding: 22px 18px; }
}
