/* ================================================================
   ARDS Infrastructure Platform — Design System v3 — Clean Ops / Indigo
   Single concept, Light / Dark theme
   ================================================================ */

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg-page);
  color: var(--text-primary);
  transition: background 0.25s ease, color 0.25s ease;
}

/* ================================================================
   SHARED TOKENS (theme-independent)
   ================================================================ */
:root {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  /* Spacing */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* Status */
  --status-ok: #10b981;
  --status-warn: #f59e0b;
  --status-error: #ef4444;
  --status-info: #3b82f6;

  /* Environment */
  --env-dev: #3b82f6;
  --env-qa: #f97316;
  --env-prod: #22c55e;
  --env-staging: #8b5cf6;

  /* Cloud brand */
  --aws-color: #ff9900;
  --gcp-color: #4285f4;

  /* Transition */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --duration-fast: 0.12s;
  --duration-normal: 0.2s;

  /* Layout */
  --sidebar-width: 260px;

  /* Radius — shared across themes */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* ================================================================
   LIGHT THEME
   ================================================================ */
[data-theme="light"],
:root:not([data-theme]) {
  --bg-page: #fafafa;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f4f4f5;
  --bg-elevated: #ffffff;
  --bg-inset: #f4f4f5;

  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-tertiary: #a1a1aa;
  --text-on-accent: #ffffff;

  --border-default: #e4e4e7;
  --border-strong: #d4d4d8;
  --border-subtle: #f4f4f5;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --shadow-card: 0 1px 2px rgba(0,0,0,0.04);

  --accent: #4f46e5;
  --accent-bg: rgba(79, 70, 229, 0.07);
  --accent-border: rgba(79, 70, 229, 0.18);
  --accent-text: #4f46e5;

  --sidebar-bg: #ffffff;
  --sidebar-border: #e4e4e7;
  --sidebar-brand-bg: linear-gradient(135deg, #4f46e5, #6366f1);
  --sidebar-brand-text: #ffffff;

  --code-bg: #f4f4f5;
  --code-text: #27272a;

  --modal-overlay: rgba(24, 24, 27, 0.4);
}

/* ================================================================
   DARK THEME
   ================================================================ */
[data-theme="dark"] {
  --bg-page: #0a0a0a;
  --bg-surface: #18181b;
  --bg-surface-hover: #1f1f23;
  --bg-elevated: #1f1f23;
  --bg-inset: #131316;

  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-on-accent: #ffffff;

  --border-default: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-subtle: rgba(255, 255, 255, 0.04);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.25);

  --accent: #818cf8;
  --accent-bg: rgba(129, 140, 248, 0.10);
  --accent-border: rgba(129, 140, 248, 0.25);
  --accent-text: #a5b4fc;

  --sidebar-bg: #111113;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-brand-bg: linear-gradient(135deg, #4f46e5, #6366f1);
  --sidebar-brand-text: #e0e7ff;

  --code-bg: #0a0a0a;
  --code-text: #d4d4d8;

  --modal-overlay: rgba(0, 0, 0, 0.6);
}

/* ================================================================
   LAYOUT
   ================================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  padding: 36px 48px;
  min-height: 100vh;
}

@media (max-width: 1024px) {
  .main-content {
    margin-left: 0;
    padding: var(--sp-6) var(--sp-5);
  }
}

/* ================================================================
   COMPONENTS
   ================================================================ */

/* ── Page Header ───────────────────────────────────────────────── */
.page-header {
  padding: var(--sp-5) var(--sp-6);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-6);
  border: 1px solid var(--border-default);
  border-left: 4px solid var(--accent);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
}
.page-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.page-header p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ── Cards ─────────────────────────────────────────────────────── */
.ds-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  transition: all var(--duration-normal) var(--ease);
  box-shadow: var(--shadow-card);
}
.ds-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ── Stat Grid ─────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  transition: all var(--duration-normal) var(--ease);
  box-shadow: var(--shadow-sm);
}
.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Tables ────────────────────────────────────────────────────── */
.ds-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
th,
.ds-table thead th {
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border-default);
  text-align: left;
  white-space: nowrap;
}
.ds-table tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
.ds-table tbody tr:last-child td { border-bottom: none; }
.ds-table tbody tr {
  transition: background var(--duration-fast) var(--ease);
}
.ds-table tbody tr:hover {
  background: var(--bg-surface-hover);
}

/* ── Buttons ───────────────────────────────────────────────────── */
.ds-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  background: var(--bg-surface);
  color: var(--text-primary);
}
.ds-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}
.ds-btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
.ds-btn-primary:hover {
  background: #4338ca;
  border-color: #4338ca;
  opacity: 1;
  box-shadow: none;
}
[data-theme="dark"] .ds-btn-primary:hover {
  background: #6d77f0;
  border-color: #6d77f0;
}

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge-ok     { background: rgba(16, 185, 129, 0.1);  color: var(--status-ok); }
.badge-warn   { background: rgba(245, 158, 11, 0.1);  color: var(--status-warn); }
.badge-error  { background: rgba(239, 68, 68, 0.1);   color: var(--status-error); }
.badge-info   { background: rgba(59, 130, 246, 0.1);  color: var(--status-info); }
.badge-neutral { background: var(--bg-inset); color: var(--text-secondary); }

/* Phase badges */
.badge.phase-dev  { background: rgba(59,130,246,0.1);  color: #3b82f6; }
.badge.phase-qa   { background: rgba(249,115,22,0.1);  color: #f97316; }
.badge.phase-prod { background: rgba(34,197,94,0.1);   color: #22c55e; }

/* Cloud badges */
.badge.chip.aws { background: rgba(255,153,0,0.1);  color: var(--aws-color); }
.badge.chip.gcp { background: rgba(66,133,244,0.1);  color: var(--gcp-color); }

/* ── Inputs ────────────────────────────────────────────────────── */
.ds-input {
  padding: 8px 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-family: var(--font-sans);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--ease);
  width: 100%;
}
.ds-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.ds-input::placeholder { color: var(--text-tertiary); }

/* ── Gauges / Progress bars ────────────────────────────────────── */
.gauge-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-inset);
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s var(--ease-out);
}
.gauge-fill.ok    { background: var(--status-ok); }
.gauge-fill.warn  { background: var(--status-warn); }
.gauge-fill.error { background: var(--status-error); }

/* ── Code / Log blocks ─────────────────────────────────────────── */
.ds-code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  border: 1px solid var(--border-default);
  overflow-x: auto;
  line-height: 1.7;
  color: var(--code-text);
}

/* ── Modals ────────────────────────────────────────────────────── */
.ds-modal-overlay {
  position: fixed; inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(4px);
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
}
.ds-modal-overlay.open { display: flex; }

.ds-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  max-width: 480px;
  width: 92%;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s var(--ease);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Toast ─────────────────────────────────────────────────────── */
.ds-toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.ds-toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  animation: toastSlide 0.25s var(--ease-out);
}
@keyframes toastSlide {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.ds-toast.success { border-left: 3px solid var(--status-ok); }
.ds-toast.error   { border-left: 3px solid var(--status-error); }
.ds-toast.info    { border-left: 3px solid var(--status-info); }

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  transition: background 0.25s ease, border-color 0.25s ease;
  overflow: hidden;
}

.sidebar-brand {
  padding: var(--sp-4) var(--sp-4);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}
.sidebar-brand-text {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--duration-fast) var(--ease);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-2);
  min-height: 0;
}
.sidebar-section { margin-bottom: var(--sp-3); }
.sidebar-section-title {
  padding: var(--sp-1) var(--sp-3);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  margin-top: var(--sp-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  text-decoration: none;
  position: relative;
  margin: 2px 0;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover {
  background: var(--accent-bg);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-item .nav-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--duration-fast) var(--ease);
}
.nav-item-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: inherit;
}
.nav-item-icon svg { width: 16px; height: 16px; }

.sidebar-footer {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-3);
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: var(--accent);
  flex-shrink: 0;
  text-transform: uppercase;
}
.sidebar-footer-info {
  flex: 1; min-width: 0; overflow: hidden;
}
.sidebar-username {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-tertiary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--duration-fast) var(--ease);
  text-decoration: none;
  flex-shrink: 0;
}
.sidebar-logout-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--status-error);
}

/* ── Theme toggle ─────────────────────────────────────────────── */
.theme-toggle {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--duration-fast) var(--ease);
  flex-shrink: 0;
  line-height: 1;
}
.theme-toggle:hover {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ── Focus (키보드 접근성) ─────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.ds-btn:focus-visible,
.ds-input:focus-visible,
.nav-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-bg), 0 0 0 1px var(--accent);
}

/* ── Utility ───────────────────────────────────────────────────── */
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 0.82rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-secondary); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-4); }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }

/* ── Animation ─────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.animate-spin { animation: spin 1s linear infinite; }
.animate-pulse { animation: pulse 2s ease-in-out infinite; }
