/* =====================================================================
   ServiceOS — design system
   Palette: deep indigo primary, warm off-white surface, soft shadows.
   Font: Inter (falls back to system UI stack).
   ===================================================================== */

:root {
  --so-bg: #f6f7fb;
  --so-surface: #ffffff;
  --so-border: #e8e9f1;
  --so-text: #1c1d2e;
  --so-text-muted: #6b6d85;
  --so-primary: #4f46e5;
  --so-primary-dark: #4338ca;
  --so-primary-light: #eef0ff;
  --so-accent: #16b88a;
  --so-danger: #e5484d;
  --so-warning: #f5a524;
  --so-sidebar-bg: #232A45;
  --so-sidebar-text: #b8b9d4;
  --so-sidebar-active: #E2A63B;
  --so-radius: 14px;
  --so-radius-sm: 10px;
  --so-shadow: 0 1px 2px rgba(20, 20, 43, 0.04), 0 8px 24px -8px rgba(20, 20, 43, 0.08);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--so-bg);
  color: var(--so-text);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

/* ---------- App shell ---------- */
.so-shell { display: flex; min-height: 100vh; }

.so-sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--so-sidebar-bg);
  color: var(--so-sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

/* ---------- Mobile menu toggle + overlay ---------- */
.so-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  padding: 6px;
  color: var(--so-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.so-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 30, 0.5);
  z-index: 35;
}

@media (max-width: 900px) {
  .so-menu-toggle { display: inline-flex; align-items: center; }

  .so-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.25);
  }

  .so-shell.so-sidebar-open .so-sidebar { transform: translateX(0); }
  .so-shell.so-sidebar-open .so-sidebar-overlay { display: block; }
}

.so-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px 10px;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.so-brand-mark {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--so-primary), #8b7ffb);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
}

.so-nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #66678a;
  padding: 16px 12px 6px;
  font-weight: 600;
}

.so-nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--so-radius-sm);
  color: var(--so-sidebar-text);
  font-weight: 500;
  font-size: 13.5px;
  margin-bottom: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}

.so-nav-link i { font-size: 16px; width: 18px; text-align: center; opacity: 0.85; }

.so-nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }

.so-nav-link.active {
  background: var(--so-sidebar-active);
  color: #14172B;
  font-weight: 600;
}
.so-nav-link.active i { opacity: 1; }

.so-sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px;
  color: #8384a8;
}

/* ---------- Main column ---------- */
.so-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.so-topbar {
  height: 64px;
  background: var(--so-surface);
  border-bottom: 1px solid var(--so-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.so-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.so-topbar h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 900px) {
  .so-topbar { padding: 0 16px; }
  .so-topbar h1 { font-size: 15.5px; }
}

.so-user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--so-text-muted);
}

.so-user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--so-primary-light);
  color: var(--so-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.so-content { padding: 28px; flex: 1; min-width: 0; }

@media (max-width: 900px) {
  .so-content { padding: 16px; }
}

@media (max-width: 480px) {
  .so-user-chip .so-username-link,
  .so-user-chip .so-view-profile-link,
  .so-user-chip .so-chip-divider {
    display: none;
  }
}

/* ---------- Cards ---------- */
.so-card {
  background: var(--so-surface);
  border: 1px solid var(--so-border);
  border-radius: var(--so-radius);
  box-shadow: var(--so-shadow);
}

.so-card-body { padding: 22px 24px; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.so-card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--so-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.so-card-header h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

/* ---------- Stat cards ---------- */
.so-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

@media (max-width: 992px) {
  .so-stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .so-stat-grid { grid-template-columns: 1fr; }
}

.so-stat {
  background: var(--so-surface);
  border: 1px solid var(--so-border);
  border-radius: var(--so-radius);
  padding: 20px 22px;
  box-shadow: var(--so-shadow);
}

.so-stat-label {
  font-size: 12.5px;
  color: var(--so-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.so-stat-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.so-stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  margin-bottom: 14px;
}

.so-stat-icon.blue { background: var(--so-primary-light); color: var(--so-primary); }
.so-stat-icon.green { background: #e5faf3; color: var(--so-accent); }
.so-stat-icon.orange { background: #fef3e2; color: var(--so-warning); }
.so-stat-icon.red { background: #fdeaea; color: var(--so-danger); }

/* ---------- Buttons ---------- */
.btn-so-primary {
  background: var(--so-primary);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: var(--so-radius-sm);
  transition: background 0.15s ease;
}
.btn-so-primary:hover { background: var(--so-primary-dark); color: #fff; }

.btn-so-outline {
  background: transparent;
  border: 1px solid var(--so-border);
  color: var(--so-text);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: var(--so-radius-sm);
}
.btn-so-outline:hover { background: var(--so-bg); }

/* ---------- Tables ---------- */
.so-table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 13.5px; }
.so-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--so-text-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--so-border);
}
.so-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--so-border);
  vertical-align: middle;
}
.so-table tr:last-child td { border-bottom: none; }
.so-table tr:hover td { background: var(--so-bg); }

.so-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.so-badge.green { background: #e5faf3; color: #0d8f68; }
.so-badge.gray { background: #f1f1f6; color: #6b6d85; }
.so-badge.orange { background: #fef3e2; color: #b6720b; }
.so-badge.red { background: #fdeaea; color: #c22; }

/* ---------- Forms ---------- */
.so-form label {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 5px;
  display: block;
}
.so-form .form-control, .so-form .form-select {
  border-radius: var(--so-radius-sm);
  border: 1px solid var(--so-border);
  padding: 9px 12px;
  font-size: 13.5px;
}
.so-form .form-control:focus, .so-form .form-select:focus {
  border-color: var(--so-primary);
  box-shadow: 0 0 0 3px var(--so-primary-light);
}

/* ---------- Login page ---------- */
.so-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #14172B 0%, #232A45 55%, #E2A63B 130%);
  padding: 20px;
}
.so-login-card {
  width: 380px;
  max-width: 100%;
  background: #fff;
  border-radius: 18px;
  padding: 36px 34px;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.35);
}

@media (max-width: 480px) {
  .so-login-card { padding: 28px 22px; }
}

/* ---------- Empty state ---------- */
.so-empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--so-text-muted);
}
.so-empty i { font-size: 34px; margin-bottom: 10px; display: block; opacity: 0.5; }

/* ---------- Onboarding tour ---------- */
.so-tour-mask {
  position: fixed;
  background: rgba(15, 15, 30, 0.6);
  z-index: 500;
  transition: all 0.25s ease;
  pointer-events: auto;
}

.so-tour-ring {
  position: fixed;
  border: 2px solid var(--so-primary);
  border-radius: 10px;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.25);
  z-index: 501;
  pointer-events: none;
  transition: all 0.25s ease;
}

.so-tour-popover {
  position: fixed;
  width: 300px;
  background: var(--so-surface);
  border-radius: var(--so-radius);
  box-shadow: 0 20px 50px -12px rgba(0,0,0,0.4);
  padding: 20px;
  z-index: 502;
  transition: top 0.25s ease, left 0.25s ease;
}

.so-tour-popover.so-tour-centered {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  text-align: center;
}

.so-tour-step-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--so-primary);
  margin-bottom: 6px;
}

.so-tour-popover h3 {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--so-text);
}

.so-tour-popover p {
  font-size: 13.5px;
  color: var(--so-text-muted);
  line-height: 1.5;
  margin: 0 0 16px;
}

.so-tour-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.so-tour-dots {
  display: flex;
  gap: 5px;
}

.so-tour-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--so-border);
}
.so-tour-dot.active { background: var(--so-primary); width: 16px; border-radius: 3px; }

@media (max-width: 480px) {
  .so-tour-popover, .so-tour-popover.so-tour-centered { width: calc(100vw - 40px); }
}