@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap');

@tailwind base;

@tailwind components;

@tailwind utilities;

@layer base {
  :root {
    /* ── Typography ── */
    --font-heading: 'IBM Plex Mono', monospace;
    --font-body: 'IBM Plex Sans', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --font-sans: 'IBM Plex Sans', sans-serif;
    --font-display: 'Bebas Neue', sans-serif;

    --text-xs: 0.625rem;
    --text-sm: 0.75rem;
    --text-base: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;
    --text-3xl: 2.25rem;

    /* ── Spacing (4px scale) ── */
    --sp-0: 0px;
    --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;
    --sp-16: 64px;

    /* ── Border Radius ── */
    --r-xs: 2px;
    --r-sm: 4px;
    --r-md: 8px;
    --r-lg: 12px;
    --r-xl: 16px;
    --r-2xl: 24px;
    --r-full: 9999px;
    --radius: 14px;
    --radius-button: 10px;

    /* ── Transitions ── */
    --t-fast: 100ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-base: 160ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-slow: 280ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-spring: 240ms cubic-bezier(0.34, 1.56, 0.64, 1);

    /* ── Z-Index ── */
    --z-base: 0;
    --z-raised: 10;
    --z-overlay: 100;
    --z-modal: 500;
    --z-toast: 1000;

    /* ── Brand Colors (Dark Mode) ── */
    --background: 150 30% 7%;
    --foreground: 120 10% 90%;
    --card: 150 25% 10%;
    --card-foreground: 120 10% 90%;
    --popover: 150 25% 10%;
    --popover-foreground: 120 10% 90%;
    --primary: 140 40% 24%;
    --primary-foreground: 0 0% 100%;
    --secondary: 150 15% 15%;
    --secondary-foreground: 120 8% 70%;
    --muted: 150 15% 12%;
    --muted-foreground: 120 8% 55%;
    --accent: 42 55% 50%;
    --accent-foreground: 0 0% 100%;
    --accent2: #3a9e5a;
    --accent3: #2450a4;
    --teal: #22a0b2;
    --destructive: 0 70% 50%;
    --destructive-foreground: 0 0% 100%;
    --success: #4caf72;
    --success-foreground: 0 0% 100%;
    --warning: #e0ae58;
    --warning-foreground: 0 0% 100%;

    /* ── Text tints ── */
    --text-high: rgba(255, 255, 255, 0.88);
    --text-med: rgba(255, 255, 255, 0.62);
    --text-low: rgba(255, 255, 255, 0.40);
    --text-dim: rgba(255, 255, 255, 0.28);
    --text-inverse: #0e1810;

    /* ── Semantic backgrounds ── */
    --success-bg: rgba(30, 110, 56, 0.22);
    --warning-bg: rgba(201, 151, 58, 0.20);
    --danger-bg: rgba(176, 58, 46, 0.20);
    --info-bg: rgba(26, 90, 122, 0.22);

    /* ── Borders ── */
    --border: 150 15% 18%;
    --input: 150 15% 18%;
    --ring: 140 40% 30%;
    --border-light: rgba(255, 255, 255, 0.05);
    --border-strong: rgba(255, 255, 255, 0.18);
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.11);

    /* ── Shadows (Dark) ── */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.20);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.40), 0 1px 3px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.50), 0 2px 6px rgba(0, 0, 0, 0.30);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.60), 0 4px 12px rgba(0, 0, 0, 0.35);
    --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.30);
    --shadow-focus: 0 0 0 3px rgba(58, 158, 90, 0.28), 0 0 0 1px rgba(58, 158, 90, 0.55);
    --shadow-focus-amber: 0 0 0 3px rgba(201, 151, 58, 0.28), 0 0 0 1px rgba(201, 151, 58, 0.55);

    /* ── Gradients (Dark) ── */
    --body-gradient: linear-gradient(135deg, #0b1a10 0%, #0e1428 50%, #0d1a12 100%);
    --panel-gradient: linear-gradient(135deg, rgba(18, 56, 26, 0.97) 0%, rgba(14, 38, 20, 0.99) 50%, rgba(18, 36, 88, 0.95) 100%);

    /* ── Sidebar ── */
    --sidebar-background: 150 35% 5%;
    --sidebar-foreground: 120 8% 65%;
    --sidebar-primary: 140 40% 24%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 150 25% 10%;
    --sidebar-accent-foreground: 120 10% 90%;
    --sidebar-border: 150 15% 14%;
    --sidebar-ring: 140 40% 24%;
  }

  .light {
    /* ── Brand Colors (Light Mode) ── */
    --background: 150 8% 92%;
    --foreground: 150 25% 15%;
    --card: 0 0% 98%;
    --card-foreground: 150 25% 15%;
    --popover: 0 0% 98%;
    --popover-foreground: 150 25% 15%;
    --primary: 140 55% 20%;
    --primary-foreground: 0 0% 100%;
    --secondary: 150 8% 85%;
    --secondary-foreground: 150 20% 30%;
    --muted: 150 8% 88%;
    --muted-foreground: 150 15% 40%;
    --accent: 42 55% 45%;
    --accent-foreground: 0 0% 100%;
    --accent2: #1e5c2e;
    --accent3: #1a3a7c;
    --teal: #1a7a8a;
    --success: #1e6e38;
    --success-foreground: 0 0% 100%;
    --warning: #a67c20;
    --warning-foreground: 0 0% 100%;

    /* ── Text tints ── */
    --text-high: #1a3020;
    --text-med: #3d6145;
    --text-low: #5c7e62;
    --text-dim: #8aab90;
    --text-inverse: #ffffff;

    /* ── Semantic backgrounds ── */
    --success-bg: rgba(30, 110, 56, 0.10);
    --warning-bg: rgba(201, 151, 58, 0.12);
    --danger-bg: rgba(176, 58, 46, 0.10);
    --info-bg: rgba(26, 90, 122, 0.10);

    /* ── Borders ── */
    --border: 150 8% 82%;
    --input: 150 8% 82%;
    --ring: 140 55% 25%;
    --border-light: rgba(30, 92, 46, 0.08);
    --border-strong: rgba(30, 92, 46, 0.28);
    --input-bg: var(--surface, #f9f8f4);
    --input-border: rgba(30, 92, 46, 0.14);

    /* ── Shadows (Light) ── */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(30, 92, 46, 0.10), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 24px rgba(30, 92, 46, 0.12), 0 2px 6px rgba(0, 0, 0, 0.07);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-focus: 0 0 0 3px rgba(30, 92, 46, 0.20), 0 0 0 1px rgba(30, 92, 46, 0.40);
    --shadow-focus-amber: 0 0 0 3px rgba(201, 151, 58, 0.20), 0 0 0 1px rgba(201, 151, 58, 0.40);

    /* ── Gradients (Light) ── */
    --body-gradient: linear-gradient(135deg, #edf0ec 0%, #eaeef6 50%, #edf0ec 100%);
    --panel-gradient: linear-gradient(135deg, #f9f8f4 0%, #f0ede5 100%);

    /* ── Sidebar ── */
    --sidebar-background: 150 8% 88%;
    --sidebar-foreground: 150 20% 30%;
    --sidebar-primary: 140 55% 20%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 150 8% 82%;
    --sidebar-accent-foreground: 150 25% 15%;
    --sidebar-border: 150 8% 78%;
    --sidebar-ring: 140 55% 25%;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.55;
    background: var(--body-gradient);
    color: var(--text-high);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100vh;
    height: 100svh;
  }

  .app-main {
    padding: var(--sp-6);
    padding-bottom: var(--sp-16);
    scrollbar-width: thin;
    scrollbar-color: rgba(201,151,58,0.60) rgba(30,92,46,0.10);
    scrollbar-gutter: stable;
  }

  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    @apply font-bold tracking-tight;
  }

  /* ── Scrollbar ── */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-track {
    background: rgba(30, 92, 46, 0.10);
  }
  ::-webkit-scrollbar-thumb {
    background: rgba(201, 151, 58, 0.55);
    border-radius: 99px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(201, 151, 58, 0.85);
  }
  * {
    scrollbar-width: thin;
    scrollbar-color: rgba(201, 151, 58, 0.60) rgba(30, 92, 46, 0.10);
  }
}

@layer components {
  /* ── Panel / Card ── */
  .panel {
    background: var(--panel-gradient);
    backdrop-filter: blur(12px);
    border: 1px solid hsl(var(--border));
    border-radius: var(--r-lg);
    padding: var(--sp-6);
    margin-bottom: var(--sp-6);
    box-shadow: var(--shadow-md);
    transition: box-shadow var(--t-base), transform var(--t-base);
  }
  .panel:hover {
    box-shadow: var(--shadow-lg);
  }
  .panel--flat {
    box-shadow: var(--shadow-xs);
    border-radius: var(--r-md);
  }
  .panel--inset {
    background: hsl(var(--secondary));
    box-shadow: var(--shadow-inset);
    border-radius: var(--r-md);
  }
  .panel-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    letter-spacing: 2px;
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
  }
  .panel-title::before {
    content: '';
    width: 4px;
    height: 1.4em;
    background: linear-gradient(180deg, var(--accent), var(--accent2));
    border-radius: var(--r-full);
    flex-shrink: 0;
  }
  .panel-subtitle {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 2px;
    color: hsl(var(--muted-foreground));
  }

  /* ── Legacy panel-card (kept for backwards compat) ── */
  .panel-card {
    @apply relative overflow-hidden;
    background: var(--panel-gradient);
    backdrop-filter: blur(20px);
    border: 1px solid hsl(var(--border));
    border-radius: var(--r-xl);
    padding: var(--sp-6);
    box-shadow: var(--shadow-lg);
  }
  .panel-card::before {
    content: '';
    @apply absolute top-0 left-0 w-full h-[1px];
    background: linear-gradient(90deg, transparent, hsl(var(--primary) / 0.2), transparent);
  }

  /* ── Glass pill ── */
  .glass-pill {
    @apply border;
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.10);
    backdrop-filter: blur(4px);
    border-radius: var(--r-full);
    padding: 4px var(--sp-4);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-high);
    font-family: var(--font-mono);
  }

  /* ── Buttons ── */
  .btn {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-md);
    border: 1.5px solid transparent;
    transition: all var(--t-base);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    line-height: 1;
    height: 36px;
    white-space: nowrap;
    font-weight: 600;
    text-decoration: none;
  }
  .btn:active {
    transform: translateY(1px) scale(0.98);
  }
  .btn:disabled {
    opacity: 0.48;
    pointer-events: none;
    box-shadow: none;
    transform: none;
  }

  .btn-primary {
    background: linear-gradient(135deg, #e0ae58 0%, #c9973a 50%, #a8792c 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(201, 151, 58, 0.35);
    border-color: rgba(201, 151, 58, 0.50);
  }
  .btn-primary:hover {
    filter: brightness(1.10);
    box-shadow: 0 4px 16px rgba(201, 151, 58, 0.45);
    transform: translateY(-1px);
  }

  .btn-secondary {
    background: linear-gradient(135deg, #2a7a42 0%, #1e5c2e 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(30, 92, 46, 0.35);
    border-color: rgba(30, 92, 46, 0.50);
  }
  .btn-secondary:hover {
    filter: brightness(1.10);
    box-shadow: 0 4px 16px rgba(30, 92, 46, 0.45);
    transform: translateY(-1px);
  }

  .btn-ghost {
    background: transparent;
    color: hsl(var(--secondary-foreground));
    border-color: var(--border-strong);
  }
  .btn-ghost:hover {
    background: hsl(var(--muted));
    color: var(--text-high);
  }

  .btn-danger {
    background: transparent;
    color: var(--destructive);
    border-color: var(--danger-bg);
  }
  .btn-danger:hover {
    background: var(--danger-bg);
    color: var(--destructive);
  }

  .btn-sm {
    height: 28px;
    padding: 4px var(--sp-3);
    font-size: var(--text-xs);
    border-radius: var(--r-sm);
  }
  .btn-lg {
    height: 44px;
    padding: var(--sp-3) var(--sp-6);
    font-size: var(--text-base);
  }
  .btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Legacy btn-primary (kept for compat) ── */
  .btn-primary-legacy {
    @apply text-primary-foreground font-bold transition-all relative overflow-hidden;
    background: linear-gradient(135deg, #e0ae58 0%, #c9973a 50%, #a8792c 100%);
    padding: 10px 20px;
    border-radius: var(--radius-button);
    box-shadow: var(--shadow-md);
    border: 1px solid hsl(var(--accent) / 0.3);
    color: #fff;
  }
  .btn-primary-legacy:hover {
    filter: brightness(1.10);
    transform: scale(1.02);
  }

  /* ── Stat Card ── */
  .stat-card {
    background: var(--panel-gradient);
    backdrop-filter: blur(12px);
    border: 1px solid hsl(var(--border));
    border-radius: var(--r-lg);
    padding: var(--sp-5);
    position: relative;
    overflow: hidden;
    transition: all var(--t-base);
  }
  .stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
  }
  .stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }
  .stat-card__label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 2px;
    color: hsl(var(--muted-foreground));
  }
  .stat-card__value {
    font-family: var(--font-display);
    font-size: var(--text-3xl);
    color: var(--accent);
    line-height: 1.1;
  }
  .stat-card__sub {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: hsl(var(--muted-foreground));
  }

  /* ── Badges ── */
  .badge {
    display: inline-flex;
    align-items: center;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    letter-spacing: 0.8px;
    padding: 2px 10px;
    border-radius: var(--r-full);
    border: 1px solid transparent;
    white-space: nowrap;
    text-transform: uppercase;
  }
  .badge-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success);
  }
  .badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: var(--warning);
  }
  .badge-danger {
    background: var(--danger-bg);
    color: var(--destructive);
    border-color: var(--destructive);
  }
  .badge-info {
    background: var(--info-bg);
    color: var(--teal);
    border-color: var(--teal);
  }
  .badge-neutral {
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    border-color: hsl(var(--border));
  }

  /* ── Alerts ── */
  .alert {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    border: 1px solid transparent;
  }
  .alert-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success);
  }
  .alert-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: var(--warning);
  }
  .alert-danger {
    background: var(--danger-bg);
    color: var(--destructive);
    border-color: var(--destructive);
  }
  .alert-info {
    background: var(--info-bg);
    color: var(--teal);
    border-color: var(--teal);
  }

  /* ── Dividers ── */
  .divider {
    border: none;
    height: 1px;
    background: hsl(var(--border));
    margin: var(--sp-5) 0;
  }
  .divider-label {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 2px;
    color: hsl(var(--muted-foreground));
  }
  .divider-label::before,
  .divider-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--accent), transparent);
  }
  .divider-label::after {
    background: linear-gradient(90deg, transparent, var(--accent));
  }

  /* ── Progress Bar ── */
  .progress-bar {
    height: 6px;
    background: hsl(var(--muted));
    border-radius: var(--r-full);
    overflow: hidden;
    box-shadow: var(--shadow-inset);
  }
  .progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent2), var(--accent));
    border-radius: var(--r-full);
    transition: width var(--t-slow);
  }

  /* ── Skeleton ── */
  .skeleton {
    background: linear-gradient(90deg, hsl(var(--muted)) 25%, hsl(var(--secondary)) 50%, hsl(var(--muted)) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--r-sm);
  }

  /* ── Empty State ── */
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--sp-16);
    text-align: center;
    font-family: var(--font-mono);
  }
  .empty-state__icon {
    font-size: 2.5rem;
    opacity: 0.4;
    margin-bottom: var(--sp-4);
  }
  .empty-state__title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    color: hsl(var(--muted-foreground));
  }
  .empty-state__desc {
    font-size: var(--text-sm);
    color: hsl(var(--muted-foreground));
    margin-top: var(--sp-2);
  }

  /* ── Item Card ── */
  .item-card {
    background: var(--panel-gradient);
    border: 1px solid hsl(var(--border));
    border-radius: var(--r-md);
    padding: var(--sp-4);
    transition: all var(--t-base);
    cursor: pointer;
  }
  .item-card:hover {
    border-color: hsl(var(--primary));
    box-shadow: var(--shadow-md);
    transform: translateX(2px);
  }
  .item-card--active {
    border-color: var(--accent);
    background: var(--warning-bg);
  }

  /* ── Sidebar gradient ── */
  .sidebar-gradient {
    background: linear-gradient(180deg, rgba(22, 61, 34, 0.97), rgba(15, 40, 25, 0.99));
  }
  :root.light .sidebar-gradient {
    background: linear-gradient(180deg, #e0e8e0 0%, #d4ddd4 100%);
  }

  /* ── Brand Gradient ── */
  .brand-gradient {
    background: linear-gradient(135deg, #1e5c2e 0%, #c9973a 100%);
  }
  .text-brand-gradient {
    background: linear-gradient(135deg, #1e5c2e 0%, #c9973a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  /* ── Scrollbar hide utility ── */
  .scrollbar-hide::-webkit-scrollbar {
    display: none;
  }
  .scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  /* ── Focus ring utility ── */
  .focus-ring-green {
    box-shadow: var(--shadow-focus);
  }
  .focus-ring-amber {
    box-shadow: var(--shadow-focus-amber);
  }
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

/* ── Responsive: header logo sizes ── */

@media (max-width: 1024px) {
  .header-logo-wrapper svg { height: 44px !important; width: auto !important; }
}

@media (max-width: 768px) {
  .header-logo-wrapper svg { height: 34px !important; width: auto !important; }
}

@media (max-width: 480px) {
  .header-logo-wrapper svg { height: 30px !important; width: auto !important; }
}

@media (max-width: 360px) {
  .header-logo-wrapper svg { height: 26px !important; width: auto !important; }
}

@media (orientation: landscape) and (max-height: 700px) {
  .header-logo-wrapper svg { height: 34px !important; width: auto !important; }
}

@media (orientation: landscape) and (max-height: 550px) {
  .header-logo-wrapper svg { height: 26px !important; width: auto !important; }
}

@media (orientation: landscape) and (max-height: 420px) {
  .header-logo-wrapper svg { height: 22px !important; width: auto !important; }
}

/* ── Responsive: header visibility ── */

@media (max-width: 1024px) {
  .header-top-bar { display: none !important; }
}

@media (max-width: 768px) {
  .header-top-bar { display: none !important; }
}

@media (orientation: landscape) and (max-height: 700px) {
  .header-top-bar { display: none !important; }
}

/* ── Responsive: main content padding ── */

@media (max-width: 1024px) {
  .app-main { padding: var(--sp-4) !important; }
}

@media (max-width: 768px) {
  .app-main { padding: var(--sp-3) !important; }
}

@media (max-width: 360px) {
  .app-main { padding: var(--sp-2) !important; }
}
