/* ==========================================================================
   SaifOS — Personal Control Center
   Design System & Base Stylesheet (Geist / Linear Monochrome Architecture)
   ========================================================================== */

:root,
[data-theme="dark"] {
  /* Dark Mode — Carbon Zinc & Precision Micro-Borders */
  --bg-app: #09090b;
  --bg-sidebar: #0c0c0e;
  --bg-surface: #111113;
  --bg-surface-elevated: #18181b;
  --bg-surface-highlight: #222226;
  --bg-surface-active: #27272a;
  --bg-header-glass: rgba(9, 9, 11, 0.82);

  /* Borders & Dividers */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.09);
  --border-hover: rgba(255, 255, 255, 0.18);
  --border-focus: #a1a1aa;

  /* Typography */
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-inverse: #09090b;

  /* Primary Action Button (Vercel Geist style) */
  --btn-primary-bg: #fafafa;
  --btn-primary-text: #09090b;
  --btn-primary-border: #fafafa;
  --btn-primary-hover: #e4e4e7;

  /* Semantic Accents (Restrained & Functional) */
  --accent-cyan: #e4e4e7;
  --accent-cyan-subtle: rgba(255, 255, 255, 0.07);
  --accent-indigo: #a1a1aa;
  --accent-indigo-subtle: rgba(255, 255, 255, 0.06);

  --status-success: #34d399;
  --status-success-bg: rgba(16, 185, 129, 0.12);
  --status-success-border: rgba(52, 211, 153, 0.22);

  --status-warning: #fbbf24;
  --status-warning-bg: rgba(245, 158, 11, 0.12);
  --status-warning-border: rgba(251, 191, 36, 0.22);

  --status-error: #fb7185;
  --status-error-bg: rgba(244, 63, 94, 0.12);
  --status-error-border: rgba(251, 113, 133, 0.25);

  /* Elevation & Shadows */
  --shadow-card: 0 1px 2px 0 rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 16px 36px -6px rgba(0, 0, 0, 0.7);
}

[data-theme="light"] {
  /* Light Mode — Warm Alabaster Canvas & Crisp Elevated Paper Cards */
  --bg-app: #f3f4f6;
  --bg-sidebar: #ebedf0;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f8f9fa;
  --bg-surface-highlight: #eef0f3;
  --bg-surface-active: #e2e5ea;
  --bg-header-glass: rgba(243, 244, 246, 0.85);

  /* Crisp Daylight Structural Borders */
  --border-subtle: #eceef2;
  --border-default: #dfe2e8;
  --border-hover: #c1c7d0;
  --border-focus: #111827;

  /* High-Legibility Ink Typography */
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;

  /* Primary Action Button (Obsidian Ink) */
  --btn-primary-bg: #111827;
  --btn-primary-text: #ffffff;
  --btn-primary-border: #111827;
  --btn-primary-hover: #1f2937;

  /* Semantic Accents (Deep Daylight Ink Tones) */
  --accent-cyan: #111827;
  --accent-cyan-subtle: rgba(17, 24, 39, 0.06);
  --accent-indigo: #374151;
  --accent-indigo-subtle: rgba(55, 65, 81, 0.07);

  --status-success: #047857;
  --status-success-bg: #ecfdf5;
  --status-success-border: #a7f3d0;

  --status-warning: #b45309;
  --status-warning-bg: #fffbeb;
  --status-warning-border: #fde68a;

  --status-error: #be123c;
  --status-error-bg: #fff1f2;
  --status-error-border: #fecdd3;

  /* Tactile Daylight Shadows */
  --shadow-card: 0 1px 3px 0 rgba(15, 23, 42, 0.05), 0 1px 2px -1px rgba(15, 23, 42, 0.03);
  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 20px -4px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 38px -8px rgba(15, 23, 42, 0.14);
}

:root {
  /* Typography Stacks */
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Geist", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Geist Mono", Menlo, Consolas, monospace;

  /* Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Coherent Radius System (Strict 8px / 12px hierarchy) */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Snappy Micro-Transitions */
  --transition-fast: 120ms ease;
  --transition-normal: 180ms ease;
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.022em;
}

p {
  color: var(--text-secondary);
}

a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

code, pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

/* Buttons — Stark Monochrome & Tactile */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn svg,
.btn i {
  width: 15px;
  height: 15px;
  stroke-width: 1.75;
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-border);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--btn-primary-hover);
  color: var(--btn-primary-text);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-surface-highlight);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

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

.btn-sm {
  font-size: 0.78rem;
  padding: 0.42rem 0.72rem;
  border-radius: var(--radius-sm);
  gap: 0.35rem;
}

.btn-icon-only {
  padding: 0.48rem;
  border-radius: var(--radius-md);
}

/* Theme Toggle Button */
.btn-theme-toggle {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  padding: 0.45rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.btn-theme-toggle:hover {
  background-color: var(--bg-surface-highlight);
  color: var(--text-primary);
  border-color: var(--border-hover);
}
.btn-theme-toggle svg,
.btn-theme-toggle i {
  width: 16px;
  height: 16px;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: var(--space-4);
  text-align: left;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-control-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input {
  width: 100%;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:hover:not(:disabled) {
  border-color: var(--border-hover);
}

.form-input:focus {
  border-color: var(--border-focus);
}

.form-input.has-icon-left {
  padding-left: 2.5rem;
}

.form-input.has-icon-right {
  padding-right: 2.5rem;
}

.input-icon-left {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  pointer-events: none;
}

.input-action-right {
  position: absolute;
  right: 0.45rem;
  display: flex;
  align-items: center;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  line-height: 1.3;
  white-space: nowrap;
}

.badge-cyan,
.badge-indigo,
.badge-neutral {
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}

.badge-success {
  background-color: var(--status-success-bg);
  color: var(--status-success);
  border: 1px solid var(--status-success-border);
}

.badge-warning {
  background-color: var(--status-warning-bg);
  color: var(--status-warning);
  border: 1px solid var(--status-warning-border);
}

.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: currentColor;
}

/* Alerts */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.45;
  margin-bottom: var(--space-4);
}

.alert-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-content {
  flex-grow: 1;
}

.alert-error {
  background-color: var(--status-error-bg);
  color: var(--status-error);
  border: 1px solid var(--status-error-border);
}

.alert-success {
  background-color: var(--status-success-bg);
  color: var(--status-success);
  border: 1px solid var(--status-success-border);
}

.alert-warning {
  background-color: var(--status-warning-bg);
  color: var(--status-warning);
  border: 1px solid var(--status-warning-border);
}

/* Spinner */
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border-default);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive 2-column form grid inside modals */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* Modal Overlay & Card */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-6);
  position: relative;
  transform: scale(0.98);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover {
  color: var(--text-primary);
}

@media (max-width: 640px) {
  /* Prevent iOS Safari automatic viewport zoom when focusing inputs */
  .form-input,
  select.form-input,
  textarea.form-input {
    font-size: 16px;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: var(--space-2);
  }

  .modal-card {
    max-width: 100% !important;
    max-height: calc(100dvh - 1rem);
    padding: var(--space-5) var(--space-4);
    border-radius: var(--radius-xl);
  }
}
