/* CasaRoma AI - Design System Base */

/* ============ CSS Reset ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { line-height: 1.5; -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ============ Design Tokens ============ */
:root {
  /* Primary */
  --primary: #1565C0;
  --primary-dark: #0D47A1;
  --primary-light: #42A5F5;
  --primary-bg: rgba(21, 101, 192, 0.08);

  /* Accent */
  --accent: #FF6F00;
  --accent-light: #FFA040;

  /* Neutrals */
  --bg: #F5F7FA;
  --bg-card: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --text: #1A1A2E;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --border: #E5E7EB;
  --divider: #F0F0F0;

  /* Semantic */
  --success: #10B981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --error: #EF4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --info: #3B82F6;
  --info-bg: rgba(59, 130, 246, 0.1);

  /* Layout */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.12);
  --shadow-xl: 0 8px 40px rgba(0,0,0,0.16);

  --nav-height: 56px;
  --tab-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --content-max: 480px;

  /* Transitions */
  --t-fast: 150ms ease;
  --t-normal: 200ms ease;
  --t-slow: 300ms ease;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* ============ Dark Mode ============ */
[data-theme="dark"] {
  --primary: #42A5F5;
  --primary-dark: #1976D2;
  --primary-light: #90CAF9;
  --primary-bg: rgba(66, 165, 245, 0.12);

  --bg: #0F1419;
  --bg-card: #1A1F2E;
  --bg-elevated: #222837;
  --text: #E8ECF4;
  --text-secondary: #9CA3AF;
  --text-tertiary: #6B7280;
  --border: #2A3040;
  --divider: #1E2430;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-xl: 0 8px 40px rgba(0,0,0,0.5);
}

/* ============ Base Typography ============ */
body {
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--t-normal), color var(--t-normal);
}

h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 1.125rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-secondary { color: var(--text-secondary); }
.text-center { text-align: center; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* ============ Layout ============ */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--t-normal), border-color var(--t-normal);
}

.app-header__title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-content {
  flex: 1;
  padding-top: var(--nav-height);
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
}

.page {
  padding: 16px;
  display: none;
  animation: pageIn 0.2s ease;
}

.page.active {
  display: block;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ Bottom Tab Bar ============ */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  transition: background var(--t-normal), border-color var(--t-normal);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-item svg {
  width: 22px;
  height: 22px;
  transition: transform var(--t-fast);
}

.tab-item.active {
  color: var(--primary);
}

.tab-item.active svg {
  transform: scale(1.1);
}

.tab-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}

/* ============ Utility ============ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.p-16 { padding: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

/* ============ Selection ============ */
::selection { background: var(--primary-bg); color: var(--primary); }

/* ============ Safe Area ============ */
@supports (padding: max(0px)) {
  .tab-bar {
    padding-bottom: max(var(--safe-bottom), 4px);
  }
}

/* ============ Responsive Breakpoints ============ */

/* Tablet */
@media (min-width: 768px) {
  :root { --content-max: 720px; }

  .app-header {
    padding: 0 24px;
  }

  .app-header__title {
    font-size: 1.25rem;
  }

  .tab-bar {
    max-width: 560px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .page {
    padding: 20px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  :root { --content-max: 960px; }

  .app-header {
    padding: 0 32px;
  }

  .page {
    padding: 24px;
  }
}

/* Large Desktop */
@media (min-width: 1280px) {
  :root { --content-max: 1120px; }
}
