@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  /* Ink scale — mirrors tailwind.config.js `ink.*`. ink-400 and darker are
     for borders/dividers/disabled states only; ink-300 is the darkest gray
     allowed for text that carries information (passes 4.5:1 on any ink
     surface from ink-950 to ink-800). */
  --ink-950: #06070A;
  --ink-900: #0D1017;
  --ink-800: #141920;
  --ink-700: #1C2230;
  --ink-600: #28303F;
  --ink-500: #363D4A;
  --ink-400: #5E6878;
  --ink-300: #8A95A3;
  --ink-200: #AEBAC8;
  --ink-100: #D4DCE8;
  --acid: #C5FF00;
  /* Foreground-safe accent — used for text/borders/underlines instead of
     --acid. Identical to --acid in dark mode (lime glows on near-black);
     lime text/borders are nearly invisible on a light surface, so light
     mode swaps this to a deep chartreuse that still passes AA. --acid
     itself stays lime in both themes since it's only used as a *fill*
     (buttons, dots, checkbox accent-color), where legibility isn't an issue. */
  --acid-fg: #C5FF00;

  /* Same swatches as above, as "R G B" triplets instead of hex. Tailwind's
     opacity modifiers (bg-acid/10, border-ink-950/50, ...) only work when
     the theme color is a function taking a separate alpha channel — it
     can't parse an alpha suffix out of a bare hex string or var(). These
     feed tailwind.config.js's `rgb(var(--x-rgb) / <alpha-value>)` colors;
     every other var(--ink-*)/var(--acid) usage in this file (and in .erb/
     .js inline styles) keeps using the hex versions above unchanged. */
  --ink-950-rgb: 6 7 10;
  --ink-900-rgb: 13 16 23;
  --ink-800-rgb: 20 25 32;
  --ink-700-rgb: 28 34 48;
  --ink-600-rgb: 40 48 63;
  --ink-500-rgb: 54 61 74;
  --ink-400-rgb: 94 104 120;
  --ink-300-rgb: 138 149 163;
  --ink-200-rgb: 174 186 200;
  --ink-100-rgb: 212 220 232;
  --acid-rgb: 197 255 0;
  --acid-fg-rgb: 197 255 0;

  /* Status/category palette — reused for scheduled-workout state, track
     categories, calendar source, etc. instead of one-off hex per section. */
  --status-done: #4ADE80;
  --status-future: #A78BFA;
  --status-race: #FBBF24;
  --status-track: #FB923C;
  --status-gcal: #60A5FA;
  --status-bad: #F87171;

  /* Radius scale */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  /* Type scale floor — smallest size permitted for meaningful text
     (uppercase micro-labels, meta, timestamps). Below this, text becomes
     unreadable in bright light regardless of contrast. */
  --text-micro: 0.6875rem;

  --body-bg: #06070A;
  --body-bg-image: radial-gradient(ellipse at 25% 0%, rgba(12, 22, 42, 0.7) 0%, transparent 55%);
  --grain-opacity: 0.028;
  --color-scheme: dark;

  /* "Trening" nav badge — always orange, brand-fixed like acid, but the
     stock Tailwind orange-400 text used in dark mode is too washed out
     as text on a light page, so light mode deepens it (same split as
     --acid vs --acid-fg above). */
  --trening-text: #FB923C;
  --trening-text-active: #FDBA74;
  --trening-bg: rgba(251, 146, 60, 0.1);
  --trening-bg-active: rgba(251, 146, 60, 0.2);
  --trening-border: rgba(251, 146, 60, 0.2);
}

/* Light mode — same cool blue-gray hue family as dark, lightness ramp
   inverted so bg-ink-950 (page bg) / text-ink-100 (primary text) keep their
   positional meaning without touching the 40+ files that use those classes. */
[data-theme="light"] {
  --ink-950: #FAFBFC;
  --ink-900: #F2F4F7;
  --ink-800: #EAEDF1;
  --ink-700: #E0E4EA;
  --ink-600: #D2D8E0;
  --ink-500: #B7BFCB;
  --ink-400: #8891A0;
  --ink-300: #5B6472;
  --ink-200: #333A45;
  --ink-100: #12151B;
  --acid-fg: #5C7300;

  --ink-950-rgb: 250 251 252;
  --ink-900-rgb: 242 244 247;
  --ink-800-rgb: 234 237 241;
  --ink-700-rgb: 224 228 234;
  --ink-600-rgb: 210 216 224;
  --ink-500-rgb: 183 191 203;
  --ink-400-rgb: 136 145 160;
  --ink-300-rgb: 91 100 114;
  --ink-200-rgb: 51 58 69;
  --ink-100-rgb: 18 21 27;
  --acid-fg-rgb: 92 115 0;

  --status-done: #1F9D53;
  --status-future: #7C5CE0;
  --status-race: #B8860B;
  --status-track: #D96A1F;
  --status-gcal: #2B6CD4;
  --status-bad: #D64545;

  --body-bg: #FAFBFC;
  --body-bg-image: radial-gradient(ellipse at 25% 0%, rgba(210, 216, 224, 0.5) 0%, transparent 55%);
  --grain-opacity: 0.018;
  --color-scheme: light;

  --trening-text: #B5540F;
  --trening-text-active: #93430A;
  --trening-bg: rgba(217, 106, 31, 0.1);
  --trening-bg-active: rgba(217, 106, 31, 0.18);
  --trening-border: rgba(217, 106, 31, 0.3);
}

@layer base {
  html {
    scroll-behavior: smooth;
  }

  body {
    background-color: var(--body-bg);
    background-image: var(--body-bg-image);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  ::-webkit-scrollbar { width: 3px; height: 3px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--ink-600); border-radius: 2px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--acid); }

  input[type="number"],
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"],
  textarea,
  select {
    @apply bg-ink-900 border border-ink-700 rounded text-ink-100 font-mono text-sm transition-colors outline-none w-full;
    padding: 0.5rem 0.75rem;
    color-scheme: var(--color-scheme);
  }

  input:focus,
  textarea:focus,
  select:focus {
    border-color: var(--acid-fg);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--acid-fg) 15%, transparent);
  }

  input[type="number"] { -moz-appearance: textfield; }
  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

  input[type="checkbox"] {
    @apply rounded border-ink-600 bg-ink-800 text-acid cursor-pointer;
    accent-color: var(--acid);
    width: 1rem;
    height: 1rem;
  }

  input[type="radio"] {
    accent-color: var(--acid);
  }
}

@layer components {
  .nav-item {
    @apply font-condensed font-medium text-ink-300 transition-colors flex items-center;
    font-size: 0.72rem;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    padding: 0 0.875rem;
    border-bottom: 2px solid transparent;
    height: 100%;
  }
  .nav-item:hover { @apply text-ink-100; }
  .nav-item-cta {
    @apply font-condensed font-semibold flex items-center transition-opacity;
    font-size: 0.72rem;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--acid-fg);
    padding: 0 0.875rem;
    border-bottom: 2px solid var(--acid-fg);
    height: 100%;
  }
  .nav-item-cta:hover { opacity: 0.75; }

  .nav-trening {
    color: var(--trening-text);
    background: var(--trening-bg);
    border-color: var(--trening-border);
  }
  .nav-trening:hover, .nav-trening.nav-trening-active {
    color: var(--trening-text-active);
    background: var(--trening-bg-active);
  }

  .card {
    @apply bg-ink-900 border border-ink-600 rounded-md;
    padding: 1.25rem 1.5rem;
  }

  .card-label {
    @apply font-condensed font-semibold text-ink-300 uppercase;
    font-size: 0.67rem;
    letter-spacing: 0.14em;
    margin-bottom: 0.5rem;
    display: block;
  }

  .section-heading {
    @apply font-condensed font-semibold text-ink-200 uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
  }

  .metric-num {
    @apply font-display leading-none;
  }

  .btn-acid {
    @apply bg-acid font-condensed font-bold uppercase cursor-pointer rounded transition-all inline-block text-center;
    color: #06070A;
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    padding: 0.65rem 1.75rem;
    border: none;
  }
  .btn-acid:hover { opacity: 0.85; transform: translateY(-1px); }
  .btn-acid:active { transform: translateY(0); opacity: 1; }
  .btn-acid:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

  .btn-ghost {
    @apply font-condensed text-ink-300 uppercase cursor-pointer transition-colors bg-transparent border-0;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
  }
  .btn-ghost:hover { @apply text-ink-100; }

  .form-label {
    @apply font-condensed font-medium text-ink-300 uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 0.35rem;
  }

  /* Hour/minute selects of the hand-built 24h time field (see
     trip_days/_time_select) — they'd stretch to w-full like every other
     select without this. */
  .time-part {
    @apply font-mono;
    width: auto;
    padding: 0.5rem 0.35rem 0.5rem 0.5rem;
  }

  /* shared/_date_field: the text box the user types in, the native date input
     parked behind it (kept rendered so its picker can still be opened), and
     the button that opens that picker. */
  .date-field { position: relative; }
  /* Specific enough to keep room for the button even where a panel restyles
     its inputs with a padding shorthand. */
  .date-field .date-field-text { padding-right: 2.25rem; }
  .date-field input[type="date"] {
    position: absolute;
    right: 0.5rem;
    bottom: 0;
    width: 1px;
    height: 1px;
    min-width: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
  }
  .date-field-picker {
    @apply text-ink-500 transition-colors;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    padding: 0 0.7rem;
  }
  .date-field-picker:hover { color: var(--acid-fg); }
  .date-field-picker svg { width: 1rem; height: 1rem; }

  .activity-row {
    @apply border-b border-ink-600 last:border-0 transition-colors;
  }
  .activity-row:hover { background: color-mix(in srgb, var(--ink-700) 40%, transparent); }

  .status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
  }

  /* Small hover-revealed row actions (car service log edit/delete) — bare
     icon buttons with no chrome of their own until hovered. */
  .icon-btn {
    @apply text-ink-400 transition-colors cursor-pointer bg-transparent border-0;
    padding: 0;
    line-height: 1;
  }
  .icon-btn:hover { @apply text-ink-100; }
  .icon-btn.danger:hover { color: var(--status-bad); }

  /* Car service log: plaquette marking an entry as done at ASO (vs DIY). */
  .aso-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    padding: 0.05rem 0.4rem;
    border-radius: 3px;
    color: var(--acid-fg);
    border: 1px solid color-mix(in srgb, var(--acid-fg) 55%, transparent);
  }

  /* Toggle button (not a checkbox) for flagging a new service log entry as
     done at ASO — see aso_toggle_controller.js. */
  .aso-toggle {
    @apply font-condensed uppercase transition-colors cursor-pointer;
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    padding: 0.45rem 0.65rem;
    border-radius: 4px;
    border: 1px solid var(--ink-600);
    background: transparent;
    color: var(--ink-400);
  }
  .aso-toggle:hover { @apply text-ink-200; }
  .aso-toggle[data-active="true"] {
    color: var(--acid-fg);
    border-color: var(--acid-fg);
    background: color-mix(in srgb, var(--acid-fg) 12%, transparent);
  }

  .no-scrollbar::-webkit-scrollbar {
    display: none;
  }
  .no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  /* Theme toggle icon swap — sun shown in dark mode (click for light),
     moon shown in light mode (click for dark). */
  .theme-toggle-btn .icon-moon { display: none; }
  [data-theme="light"] .theme-toggle-btn .icon-sun { display: none; }
  [data-theme="light"] .theme-toggle-btn .icon-moon { display: block; }

  /* Flash banners — tint mixes the status color into the page background
     instead of a fixed hex, so a dark near-black tint in dark mode becomes
     a pale tint in light mode automatically. */
  .flash-notice {
    border-bottom: 1px solid color-mix(in srgb, var(--status-done) 35%, transparent);
    background: color-mix(in srgb, var(--status-done) 12%, var(--ink-950));
    color: var(--status-done);
  }
  .flash-alert {
    border-bottom: 1px solid color-mix(in srgb, var(--status-bad) 35%, transparent);
    background: color-mix(in srgb, var(--status-bad) 12%, var(--ink-950));
    color: var(--status-bad);
  }
}

/* Info tooltip badge */
.info-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--ink-300);
  color: var(--ink-300);
  font-size: 0.6rem;
  font-style: italic;
  font-family: Georgia, 'Times New Roman', serif;
  cursor: help;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
  line-height: 1;
}
.info-group:hover .info-badge,
.info-badge:hover { border-color: var(--acid-fg); color: var(--acid-fg); }

/* Google Places Autocomplete dropdown — Google renders this into <body>
   with its own inline white styling, so it's overridden here to match the
   site's ink/acid palette in both themes instead of clashing with them. */
.pac-container {
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: 0.375rem;
  margin-top: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-family: 'JetBrains Mono', monospace;
}
.pac-item {
  border-top-color: var(--ink-700);
  color: var(--ink-300);
  font-size: 0.72rem;
  padding: 0.5rem 0.75rem;
}
.pac-item:hover, .pac-item-selected { background: var(--ink-800); }
.pac-item-query { color: var(--ink-100); }
.pac-matched { color: var(--acid-fg); }
.pac-icon { display: none; }
.pac-logo:after { display: none; }

.info-tooltip {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 7px);
  width: 230px;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--ink-200);
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  font-family: 'Barlow', sans-serif;
  font-style: normal;
  font-weight: 400;
  white-space: normal;
}
.info-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink-600);
}
.info-group:hover .info-tooltip { opacity: 1; }

/* Morning brief markdown */
.brief-content { color: var(--ink-100); font-size: 0.875rem; line-height: 1.7; }
.brief-content h1, .brief-content h2, .brief-content h3 {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-100);
  margin-top: 1rem;
  margin-bottom: 0.25rem;
}
.brief-content h1 { font-size: 1rem; }
.brief-content h2 { font-size: 0.9rem; }
.brief-content h3 { font-size: 0.8rem; color: var(--ink-200); }
.brief-content strong { color: var(--ink-100); font-weight: 600; }
.brief-content em { color: var(--ink-200); font-style: italic; }
.brief-content ul, .brief-content ol { padding-left: 1.25rem; margin: 0.5rem 0; }
.brief-content li { margin-bottom: 0.2rem; }
.brief-content ul li { list-style-type: disc; }
.brief-content ol li { list-style-type: decimal; }
.brief-content p { margin-bottom: 0.5rem; }
.brief-content p:last-child { margin-bottom: 0; }
.brief-content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8em;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  color: var(--acid-fg);
}
.brief-content hr { border: none; border-top: 1px solid var(--ink-700); margin: 0.75rem 0; }

/* Noise grain texture */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: var(--grain-opacity);
}

/* Page entrance */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up   { animation: fadeUp 0.35s ease both; }
.fade-up-1 { animation-delay: 0.04s; }
.fade-up-2 { animation-delay: 0.09s; }
.fade-up-3 { animation-delay: 0.14s; }
.fade-up-4 { animation-delay: 0.20s; }
.fade-up-5 { animation-delay: 0.27s; }
.fade-up-6 { animation-delay: 0.34s; }

/* Praca w tle (PerfectGym — sprawdzanie grafiku): pierścień w kolorze akcentu
   z jednym jaśniejszym łukiem, żeby obrót był widoczny. Rozmiar dobrany do
   wysokości linijki tekstu obok. */
@keyframes pgSpin { to { transform: rotate(360deg); } }
.pg-spinner {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 99px;
  border: 2px solid color-mix(in srgb, var(--acid-fg) 22%, transparent);
  border-top-color: var(--acid-fg);
  animation: pgSpin 0.7s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .pg-spinner { animation-duration: 2s; }
}

/* Chat message fade in */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-in { animation: msgIn 0.2s ease both; }

/* Tension button ring glow on select */
.tension-btn-selected-1 { box-shadow: 0 0 0 2px color-mix(in srgb, var(--status-done) 40%, transparent); }
.tension-btn-selected-5 { box-shadow: 0 0 0 2px color-mix(in srgb, var(--status-bad) 40%, transparent); }

/* Google Maps InfoWindow — restyled to match the app's card look instead
   of Google's default white bubble. Class names (gm-style-iw-*,
   gm-ui-hover-effect) are internal but have been stable for years. */
.gm-style .gm-style-iw-c {
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 12px 14px;
}
.gm-style .gm-style-iw-d { overflow: auto !important; }
.gm-style .gm-style-iw-t::after { background: var(--ink-800); box-shadow: -1px 1px 1px 0 color-mix(in srgb, var(--ink-600) 60%, transparent); }
.gm-style .gm-ui-hover-effect {
  top: 4px !important;
  right: 4px !important;
  width: 22px !important;
  height: 22px !important;
  border-radius: 4px;
  opacity: 0.7;
}
.gm-style .gm-ui-hover-effect:hover { opacity: 1; }
/* The close icon is a CSS mask filled via background-color (black by
   default) — invisible against our dark bubble, so recolor the fill. */
.gm-style .gm-ui-hover-effect span {
  background-color: var(--ink-200) !important;
  width: 13px !important;
  height: 13px !important;
  margin: 4.5px !important;
}
.gm-style .gm-ui-hover-effect:hover span { background-color: var(--acid-fg) !important; }
.gm-style .gm-ui-hover-effect:focus-visible {
  outline: 1px solid var(--acid-fg);
  outline-offset: 1px;
}
