/* ================================================================
   KPR Experience v2.0 — Core Design System
   Fonts, CSS Variables, Reset, Browser Chrome, Shared Utilities
   ================================================================ */

/* -- Font Faces ------------------------------------------------- */
@font-face { font-family: 'Inter'; src: url('/fonts/inter-var.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Space Grotesk'; src: url('/fonts/space-grotesk-var.woff2') format('woff2'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'Playfair Display'; src: url('/fonts/playfair-display-var.woff2') format('woff2'); font-weight: 400 900; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('/fonts/ibm-plex-mono-var.woff2') format('woff2'); font-weight: 100 700; font-display: swap; }

/* -- Design Tokens ---------------------------------------------- */
:root {
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;

  --chrome-bg: #dee1e6;
  --chrome-tab-active: #ffffff;
  --chrome-tab-inactive: #d3d6db;
  --chrome-tab-hover: #e8eaed;
  --chrome-tab-text: #5f6368;
  --chrome-tab-text-active: #1a1a1a;
  --toolbar-bg: #ffffff;
  --toolbar-border: #dadce0;
  --address-bg: #f1f3f4;
  --address-text: #333;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --radius-lg: 12px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition-base: 250ms var(--ease-out);

  --app-bg: #ffffff;
  --app-surface: #f8f9fa;
  --app-border: #e5e7eb;
  --app-text-1: #111827;
  --app-text-2: #6b7280;
  --app-text-3: #9ca3af;
  --app-accent: #3b82f6;
  --app-accent-light: rgba(59,130,246,0.08);
}

/* -- Reset ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body); background: var(--chrome-bg); color: var(--app-text-1);
  line-height: 1.55; overflow: hidden; height: 100vh; width: 100vw;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ================================================================
   BROWSER CHROME
   ================================================================ */
.browser-frame {
  display: flex; flex-direction: column;
  width: 100vw; height: 100vh; background: var(--chrome-bg); overflow: hidden;
}

/* -- Tab Bar ---------------------------------------------------- */
.browser-tabs {
  display: flex; align-items: flex-end; gap: 1px;
  padding: 8px 12px 0; background: var(--chrome-bg);
  height: 42px; flex-shrink: 0;
  overflow-x: auto; scrollbar-width: none;
}
.browser-tabs::-webkit-scrollbar { display: none; }

.browser-tab {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 20px; min-width: 90px; max-width: 180px; height: 34px;
  font-size: 0.85rem; font-weight: 500; color: var(--chrome-tab-text);
  background: var(--chrome-tab-inactive); border-radius: 8px 8px 0 0;
  border: none; cursor: pointer; white-space: nowrap; user-select: none; flex-shrink: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.browser-tab:hover { background: var(--chrome-tab-hover); }
.browser-tab.active { background: var(--chrome-tab-active); color: var(--chrome-tab-text-active); font-weight: 600; }

/* -- Toolbar ---------------------------------------------------- */
.browser-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border); flex-shrink: 0;
}
.toolbar-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  color: var(--app-text-2); transition: background var(--transition-fast);
}
.toolbar-btn:hover:not(:disabled) { background: rgba(0,0,0,0.06); }
.toolbar-btn:disabled { opacity: 0.3; cursor: default; }
.toolbar-btn--contact {
  width: auto; padding: 6px 16px; margin-left: auto;
  border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600;
  color: #fff; background: #2563eb;
}
.toolbar-btn--contact:hover { background: #1d4ed8; }

/* -- Address Bar ------------------------------------------------ */
.address-bar {
  display: flex; align-items: center; gap: 6px; flex: 1;
  padding: 6px 12px; background: var(--address-bg); border-radius: 20px; min-width: 0;
}
.address-bar__lock { color: var(--app-text-3); flex-shrink: 0; }
.address-bar__url {
  font-size: 0.85rem; color: var(--address-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* -- Viewport --------------------------------------------------- */
.browser-viewport { flex: 1; overflow: hidden; position: relative; background: var(--app-bg); }
.tab-panel { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; background: var(--app-bg); }
.tab-panel[hidden] { display: none; }

/* ================================================================
   SHARED UTILITIES
   ================================================================ */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.text-mono { font-family: var(--font-mono); }
.text-display { font-family: var(--font-display); }
.text-muted { color: var(--app-text-2); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.78rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* -- Buttons ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 500;
  transition: all var(--transition-fast); white-space: nowrap; cursor: pointer; border: 1px solid transparent;
}
.btn--primary { background: var(--app-accent); color: #fff; border-color: var(--app-accent); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { background: transparent; border-color: var(--app-border); color: var(--app-text-2); }
.btn--ghost:hover { background: var(--app-accent-light); color: var(--app-accent); border-color: var(--app-accent); }
.btn--sm { padding: 5px 12px; font-size: 0.8rem; }
.btn--lg { padding: 10px 24px; font-size: 0.95rem; }

/* -- Badges ----------------------------------------------------- */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 99px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge--green  { background: #dcfce7; color: #166534; }
.badge--yellow { background: #fef3c7; color: #92400e; }
.badge--red    { background: #fee2e2; color: #991b1b; }
.badge--blue   { background: #dbeafe; color: #1e40af; }
.badge--gray   { background: #f3f4f6; color: #4b5563; }
.badge--purple { background: #ede9fe; color: #5b21b6; }
.app-dark .badge--green  { background: rgba(34,197,94,0.15); color: #4ade80; }
.app-dark .badge--yellow { background: rgba(234,179,8,0.15); color: #fbbf24; }
.app-dark .badge--red    { background: rgba(239,68,68,0.15); color: #f87171; }
.app-dark .badge--blue   { background: rgba(59,130,246,0.15); color: #60a5fa; }
.app-dark .badge--gray   { background: rgba(156,163,175,0.15); color: #9ca3af; }
.app-dark .badge--purple { background: rgba(139,92,246,0.15); color: #a78bfa; }

/* -- Form Fields ------------------------------------------------ */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--app-text-2); }
.form-input, .form-select, .form-textarea {
  padding: 8px 12px; border: 1px solid var(--app-border); border-radius: var(--radius-xs);
  background: var(--app-surface); color: var(--app-text-1); font-size: 0.9rem;
  transition: border-color var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--app-accent); box-shadow: 0 0 0 3px var(--app-accent-light);
}
.form-input--error { border-color: #ef4444 !important; }
.form-textarea { resize: vertical; min-height: 80px; }
.app-dark .form-input, .app-dark .form-select, .app-dark .form-textarea { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.1); color: #f0f0f5; }
.app-dark .form-label { color: #a0a0b0; }

/* -- Data Tables ------------------------------------------------ */
.data-table { width: 100%; font-size: 0.85rem; }
.data-table th { text-align: left; padding: 10px 14px; font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--app-text-3); border-bottom: 2px solid var(--app-border); cursor: pointer; user-select: none; }
.data-table th:hover { color: var(--app-text-1); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--app-border); vertical-align: middle; }
.data-table tr:hover td { background: var(--app-accent-light); }
.data-table .sort-asc::after { content: ' \2191'; }
.data-table .sort-desc::after { content: ' \2193'; }
.app-dark .data-table th { color: rgba(255,255,255,0.4); border-color: rgba(255,255,255,0.08); }
.app-dark .data-table td { border-color: rgba(255,255,255,0.06); }
.app-dark .data-table tr:hover td { background: rgba(255,255,255,0.03); }

/* -- Cards ------------------------------------------------------ */
.card { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius); padding: 16px; }
.app-dark .card { background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.08); }

/* -- KPI Cards -------------------------------------------------- */
.kpi-grid { display: grid; gap: 16px; }
.kpi-card { display: flex; flex-direction: column; gap: 6px; padding: 18px 20px; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius); }
.kpi-card__label { font-size: 0.78rem; font-weight: 500; color: var(--app-text-2); }
.kpi-card__value { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 700; color: var(--app-text-1); }
.kpi-card__change { font-size: 0.78rem; font-weight: 500; }
.kpi-card__change--up { color: #16a34a; }
.kpi-card__change--down { color: #dc2626; }
.app-dark .kpi-card { background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.08); }
.app-dark .kpi-card__value { color: #f0f0f5; }
.app-dark .kpi-card__change--up { color: #4ade80; }
.app-dark .kpi-card__change--down { color: #f87171; }

/* -- Image Placeholder ------------------------------------------ */
.img-placeholder {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb); border-radius: var(--radius-sm);
  color: #9ca3af; font-size: 0.78rem; letter-spacing: 0.03em;
}
.app-dark .img-placeholder { background: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.06)); color: rgba(255,255,255,0.3); }

/* -- Empty State ------------------------------------------------ */
.empty-state { display: flex; align-items: center; justify-content: center; padding: 48px 24px; text-align: center; font-size: 0.9rem; color: var(--app-text-3); }

/* -- Focus ------------------------------------------------------ */
:focus-visible { outline: 2px solid var(--app-accent); outline-offset: 2px; }
::selection { background: rgba(59,130,246,0.2); }

/* -- Tab-specific overrides ------------------------------------- */
[data-tab="dashboard"], [data-tab="erp"], [data-tab="crm"] { color: #f0f0f5; }
