:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-soft: #e0f2fe;
  --accent: #0ea5e9;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e3a5f;
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.12);
  --radius: 12px;
  --radius-lg: 16px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --sidebar-width: 248px;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.login-brand {
  background: linear-gradient(145deg, #0f172a 0%, #1e3a5f 45%, #0369a1 100%);
  color: #fff;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(14, 165, 233, 0.25) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(56, 189, 248, 0.15) 0%, transparent 45%);
  pointer-events: none;
}

.login-brand-inner { position: relative; z-index: 1; }

.brand-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.35);
  margin-bottom: 28px;
}

.login-brand h1 {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-brand .tagline {
  color: #94a3b8;
  font-size: 15px;
  max-width: 360px;
  margin: 0 0 40px;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 16px;
}

.feature-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: #cbd5e1;
  font-size: 14px;
}

.feature-list .icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

.login-brand-footer {
  position: relative;
  z-index: 1;
  color: #64748b;
  font-size: 12px;
}

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-md);
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 28px;
}

.login-hint {
  margin-top: 20px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--border);
}

/* ── App shell ── */
.app {
  display: none;
  min-height: 100vh;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar);
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid #1e293b;
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand .logo-sm {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 14px;
}

.sidebar-brand .title {
  color: #f1f5f9;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
}

.sidebar-brand .version {
  font-size: 11px;
  color: #64748b;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  opacity: 0.85;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.admin-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  margin-bottom: 10px;
}

.admin-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #334155, #475569);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.admin-chip .name {
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 500;
}

.admin-chip .role {
  color: #64748b;
  font-size: 11px;
}

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main-content {
  flex: 1;
  padding: 24px 28px 32px;
  overflow: auto;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.card-header h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}

.card-header p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.card-toolbar {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Stats ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-soft); color: var(--primary); }
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-icon.slate { background: #f1f5f9; color: #475569; }

.stat-card .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-grid.single { grid-template-columns: 1fr; }

label.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

textarea { resize: vertical; min-height: 72px; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.proto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.proto-grid label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.proto-grid label:hover {
  border-color: var(--accent);
  background: var(--primary-soft);
}

.proto-grid input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--primary);
}

.proto-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 8px 0 12px;
}

.proto-search {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.proto-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.proto-brand-group {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.proto-brand-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 4px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.proto-grid label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px rgba(2, 132, 199, 0.15);
}

.proto-grid label span b {
  color: var(--primary);
  font-weight: 600;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-soft);
  color: #0369a1;
  padding: 3px 8px;
  border-radius: 6px;
  margin: 0 4px 4px 0;
  font-size: 11px;
  font-weight: 500;
}

.tag-brand {
  background: rgba(255, 255, 255, 0.65);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10px;
  color: var(--muted);
}

.confirm-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.search-input {
  width: 220px;
  min-width: 160px;
}

.proto-grid label.hidden-by-search {
  display: none;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal {
  width: 100%;
  max-width: 720px;
  max-height: min(90vh, 860px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.modal-close:hover {
  background: #eef2f6;
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
  overflow: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

.user-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.user-detail-grid .full {
  grid-column: 1 / -1;
}

.detail-readonly {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}

.detail-readonly code {
  font-size: 12px;
}

@media (max-width: 640px) {
  .user-detail-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; }
}

/* ── Buttons ── */
button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

button:active { transform: scale(0.98); }

.btn {
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  box-shadow: 0 1px 2px rgba(2, 132, 199, 0.25);
}

.btn:hover { background: var(--primary-hover); }

.btn.secondary {
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

.btn.secondary:hover { background: #eef2f6; }

.btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn.ghost:hover { background: var(--surface-2); }

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.danger:hover { background: #b91c1c; }

.btn.sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-block { width: 100%; }

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Tables ── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: var(--surface-2);
}

th {
  text-align: left;
  padding: 12px 14px;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: 0; }

tbody tr:hover { background: #fafbfc; }

td code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Tags & status ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: #f1f5f9; color: var(--muted); }

.muted { color: var(--muted); font-size: 12px; }
.ok { color: var(--success); }
.bad { color: var(--danger); }

.machine-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 12px;
}

.gap-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  min-width: 100px;
}

.gap-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #059669, #0284c7);
}

.gap-bar-warn > span {
  background: linear-gradient(90deg, #f59e0b, #dc2626);
}

.msg {
  margin-top: 12px;
  font-size: 13px;
  min-height: 18px;
  padding: 10px 14px;
  border-radius: 10px;
}

.msg.ok {
  background: var(--success-soft);
  color: #047857;
}

.msg.bad {
  background: var(--danger-soft);
  color: #b91c1c;
}

.msg.info {
  background: var(--primary-soft);
  color: #0369a1;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

.empty-state .icon { font-size: 32px; margin-bottom: 12px; opacity: 0.5; }

@media (max-width: 960px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .sidebar { width: 72px; }
  .sidebar-brand .title, .sidebar-brand .version, .nav-item span, .admin-chip .name, .admin-chip .role { display: none; }
  .sidebar-header { padding: 16px 12px; }
  .nav-item { justify-content: center; padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
}
