/* ==========================================
   PersonalOS — Design System v1.0.0
   Principle: Minimal · Spacious · Consistent · Accessible
   ========================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Surfaces (M3 Dark Tonal Elevation) */
  --bg-base:      #0b0e14;
  --bg-surface:   #121824;
  --bg-elevated:  #1a2334;
  --bg-overlay:   rgba(11, 14, 20, 0.75);

  /* Borders */
  --border:       #1e293b;
  --border-hover: #334155;
  --border-focus: #3b82f6;

  /* Text Hierarchy */
  --text-primary:   #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --text-inverse:   #0f172a;

  /* Brand / Accent Defaults */
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim:   rgba(59, 130, 246, 0.14);
  --success:      #10b981;
  --success-dim:  rgba(16, 185, 129, 0.14);
  --warning:      #f59e0b;

  /* Typography */
  --font:       'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
  --font-khmer: 'Noto Sans Khmer', sans-serif;

  /* Layout & Shadows */
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --shadow-sm:  0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow:     0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg:  0 16px 48px rgba(0, 0, 0, 0.50);
}

[data-theme="light"] {
  /* Surfaces (M3 Light Tonal Elevation) */
  --bg-base:      #f8fafc;
  --bg-surface:   #ffffff;
  --bg-elevated:  #f1f5f9;
  --bg-overlay:   rgba(15, 23, 42, 0.40);

  /* Borders */
  --border:       #e2e8f0;
  --border-hover: #cbd5e1;
  --border-focus: #3b82f6;

  /* Text Hierarchy */
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --text-inverse:   #ffffff;

  --accent-dim:   rgba(59, 130, 246, 0.08);
  --success-dim:  rgba(16, 185, 129, 0.08);

  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow:     0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg:  0 12px 36px rgba(0, 0, 0, 0.12);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font);
  background-color: var(--bg-base);
  color: var(--text-primary);
  margin: 0; padding: 0;
  min-height: 100vh;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
  transition: background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body[lang="km"] { font-family: var(--font-khmer), var(--font); }
.font-mono      { font-family: var(--font-mono) !important; }
.font-khmer     { font-family: var(--font-khmer) !important; }

/* ---------- Card System ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.2s ease,
              box-shadow 0.2s ease,
              transform 0.2s ease;
}

.card-interactive:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow), 0 0 16px var(--accent-dim);
  transform: translateY(-2px);
  cursor: pointer;
}

.card-accent:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 24px var(--accent-dim);
  transform: translateY(-2px);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font); font-size: 0.8125rem; font-weight: 600;
  padding: 0.5rem 1rem; border-radius: var(--radius);
  border: none; cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap; text-decoration: none;
}
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(59,130,246,0.35); }

.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-hover); }

.btn-icon {
  padding: 0.45rem; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-secondary);
}
.btn-icon:hover { color: var(--text-primary); border-color: var(--border-hover); background: var(--bg-surface); }

/* ---------- Navigation ---------- */
.nav-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem; font-weight: 500;
  color: var(--text-secondary);
  background: transparent; border: none; cursor: pointer;
  transition: color 0.2s ease;
  text-decoration: none;
  position: relative;
}
.nav-link::after {
  content: '';
  position: absolute; bottom: -2px; left: 50%; right: 50%;
  height: 2px; border-radius: 2px;
  background: var(--accent);
  transition: left 0.2s ease, right 0.2s ease;
}
.nav-link:hover { color: var(--text-primary); }
.nav-link.active { color: var(--accent); font-weight: 600; }
.nav-link.active::after { left: 12px; right: 12px; }

/* ---------- Theme Color Picker ---------- */
.theme-picker-panel {
  position: absolute; top: calc(100% + 10px); right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 220px;
  opacity: 0; pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.theme-picker-panel.open {
  opacity: 1; pointer-events: auto;
  transform: translateY(0);
}
.theme-picker-title {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  margin: 0 0 0.625rem;
}
.theme-swatches {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px;
}
.theme-swatch {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
  flex-shrink: 0;
}
.theme-swatch:hover { transform: scale(1.2); }
.theme-swatch.selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 3px var(--bg-base), 0 0 0 5px currentColor;
  transform: scale(1.15);
}

/* Admin Sidebar nav link */
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 0.5rem 0.75rem; border-radius: var(--radius);
  font-size: 0.8125rem; font-weight: 500;
  color: var(--text-secondary);
  background: transparent; border: none; cursor: pointer; width: 100%;
  text-align: left;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.sidebar-link:hover { color: var(--text-primary); background: var(--bg-elevated); border-left-color: var(--border-hover); }
.sidebar-link.active {
  color: var(--accent); background: var(--accent-dim);
  font-weight: 600; border-left-color: var(--accent);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.15rem 0.5rem; border-radius: var(--radius-sm);
  font-size: 0.7rem; font-weight: 600; font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

.badge-blue   { background: var(--accent-dim);   color: #60a5fa; border: 1px solid rgba(59,130,246,0.2); }
.badge-green  { background: var(--success-dim);  color: #34d399; border: 1px solid rgba(16,185,129,0.2); }
.badge-amber  { background: rgba(245,158,11,.1); color: #fbbf24; border: 1px solid rgba(245,158,11,.2); }
.badge-muted  { background: var(--bg-elevated);  color: var(--text-secondary); border: 1px solid var(--border); }

/* ---------- Forms ---------- */
.input {
  width: 100%; padding: 0.55rem 0.75rem;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  font-family: var(--font); font-size: 0.8125rem;
  outline: none; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input::placeholder { color: var(--text-muted); }
.input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }

textarea.input { resize: vertical; min-height: 90px; }
label.field-label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }

/* ---------- Section Header ---------- */
.section-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.875rem; margin-bottom: 1.25rem;
}
.section-title {
  font-size: 1.125rem; font-weight: 700;
  color: var(--text-primary); margin: 0 0 2px;
}
.section-desc { font-size: 0.75rem; color: var(--text-secondary); margin: 0; }

/* ---------- Skill Progress Bar ---------- */
.skill-bar {
  height: 4px; background: var(--bg-elevated);
  border-radius: 99px; overflow: hidden;
}
.skill-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--success));
}

/* ---------- Timeline ---------- */
.timeline-line { border-left: 2px solid var(--border); }
.timeline-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-base);
}

/* ---------- Code Block ---------- */
.code-block {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.code-block-header {
  padding: 0.5rem 0.875rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex; align-items: center; justify-content: space-between;
}
.code-block pre {
  padding: 1rem; margin: 0; overflow-x: auto;
  font-family: var(--font-mono); font-size: 0.78rem; line-height: 1.6;
  color: var(--text-primary);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(6px);
  z-index: 200; display: flex;
  align-items: center; justify-content: center; padding: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-box {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 34rem;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}

/* ---------- Divider ---------- */
.divider { border: none; border-top: 1px solid var(--border); margin: 0; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ---------- Animations ---------- */
.fade-in {
  animation: fadeSlideUp 0.22s cubic-bezier(0.4, 0, 0.2, 1) both;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Legacy aliases so old Tailwind template strings still resolve */
.pos-card         { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); transition: all 0.2s ease; }
.pos-card-hover:hover { border-color: var(--border-hover); box-shadow: var(--shadow); transform: translateY(-2px); }
.badge-tag        { display: inline-flex; align-items: center; padding: 0.15rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.7rem; font-weight: 600; font-family: var(--font-mono); background: var(--accent-dim); color: #60a5fa; border: 1px solid rgba(59,130,246,0.2); }
.badge-emerald    { display: inline-flex; align-items: center; padding: 0.15rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.7rem; font-weight: 600; font-family: var(--font-mono); background: var(--success-dim); color: #34d399; border: 1px solid rgba(16,185,129,0.2); }
.nav-tab-btn      { display: inline-flex; align-items: center; gap: 6px; padding: 0.4rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.8125rem; font-weight: 500; color: var(--text-secondary); background: transparent; border: none; cursor: pointer; transition: all 0.15s ease; }
.nav-tab-btn:hover { color: var(--text-primary); background: var(--bg-elevated); }
.nav-tab-btn.active { color: #fff; background: var(--accent); font-weight: 600; }
.animate-fade-in  { animation: fadeSlideUp 0.22s cubic-bezier(0.4, 0, 0.2, 1) both; }

/* Light mode scrollbar */
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c8d5e4; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #a0b4c8; }
