/* ============================================================
   Rank Tracker — Global Styles (Dark Mode)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  /* Jaśniejsze powierzchnie + mocniejsze obramowania = lepsza czytelność na LCD */
  --bg-base:       #050B14;
  --bg-surface:    #0F172A;
  --bg-elevated:   #1E293B;
  --bg-hover:      #334155;
  --border:        #334155;
  --border-light:  #475569;

  --text-primary:  #F8FAFC;
  --text-secondary:#CBD5E1;
  --text-muted:    #94A3B8;

  --accent:        #06B6D4;
  --accent-hover:  #0891B2;
  --accent-light:  rgba(6, 182, 212, 0.18);

  --green:         #10B981;
  --green-light:   rgba(16, 185, 129, 0.15);
  --red:           #EF4444;
  --red-light:     rgba(239, 68, 68, 0.15);
  --yellow:        #F59E0B;
  --yellow-light:  rgba(245, 158, 11, 0.15);

  --sidebar-w:     280px;
  --topbar-h:      70px;
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     16px;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:     0 2px 8px rgba(0,0,0,0.3);
  --shadow-card:   0 1px 0 rgba(255,255,255,0.05) inset, 0 12px 40px rgba(0,0,0,0.28);
  --content-max:   96%;
}

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

html { font-size: 18px; }

::selection {
  background: rgba(123, 140, 255, 0.35);
  color: var(--text-primary);
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ─────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(6, 182, 212, 0.08), transparent 55%),
    radial-gradient(900px 500px at 10% 100%, rgba(59, 130, 246, 0.05), transparent 50%),
    var(--bg-base);
}

.topbar {
  height: var(--topbar-h);
  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(18px, 3vw, 32px);
  position: sticky;
  top: 0;
  z-index: 90;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
}

.page-content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: clamp(20px, 3.5vw, 36px) clamp(18px, 3vw, 32px) 40px;
  flex: 1;
}

/* ── Sidebar brand ──────────────────────────────────────────── */

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sidebar-brand-sub {
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 400;
  opacity: 0.9;
}

/* ── Sidebar nav ────────────────────────────────────────────── */

.sidebar-nav { padding: 12px 10px; flex: 1; }

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 16px 10px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
  margin-bottom: 2px;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-light);
  color: #e0e7ff;
  font-weight: 600;
}

.nav-link svg { flex-shrink: 0; opacity: 0.8; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* ── Topbar elements ────────────────────────────────────────── */

.topbar-title {
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:active:not(:disabled) { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); }

.btn-danger {
  background: transparent;
  color: #fca5a5;
  border: 1px solid rgba(248,113,113,0.45);
}
.btn-danger:hover { background: var(--red-light); }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-xs { padding: 3px 8px; font-size: 0.75rem; }

.btn-icon {
  width: 34px; height: 34px; padding: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ── Cards ──────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}

.card-lg { padding: 28px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ── Metric cards ───────────────────────────────────────────── */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.metric-grid--dense {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: var(--shadow-card);
}

.metric-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset, 0 16px 48px rgba(0,0,0,0.35);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), #3b82f6);
}

.metric-icon {
  width: 40px; height: 40px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: 14px;
}

.metric-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.metric-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ── Tables ─────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  table-layout: fixed;
}

thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }
tbody tr:hover { background: rgba(6, 182, 212, 0.09); }

tbody td {
  padding: 14px 16px;
  color: var(--text-primary);
  vertical-align: middle;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ── Position badges ────────────────────────────────────────── */

.pos {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

.pos-top3    { background: rgba(251,191,36,0.18); color: #fcd34d; border: 1px solid rgba(251,191,36,0.45); }
.pos-top10   { background: var(--green-light);    color: #6ee7b7; border: 1px solid rgba(52,211,153,0.45); }
.pos-top30   { background: var(--accent-light);   color: #67e8f9; border: 1px solid rgba(6,182,212,0.45); }
.pos-low     { background: var(--bg-elevated);    color: var(--text-secondary); border: 1px solid var(--border-light); }
.pos-none    { background: var(--bg-elevated);    color: var(--text-secondary); border: 1px solid var(--border); font-style: italic; font-weight: 500; }

/* ── Change badges ──────────────────────────────────────────── */

.change { display: inline-flex; align-items: center; gap: 3px; font-size: 0.8rem; font-weight: 600; }
.change-up   { color: var(--green); }
.change-down { color: var(--red); }
.change-flat { color: var(--text-secondary); }

/* ── Forms ──────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 42px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.875rem;
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
}

textarea { min-height: 100px; }

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

select option { background: var(--bg-elevated); }

.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Alerts ─────────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-error   { background: var(--red-light);    border: 1px solid rgba(248,113,113,0.4);  color: #fecaca; }
.alert-success { background: var(--green-light); border: 1px solid rgba(52,211,153,0.4);   color: #d1fae5; }
.alert-info    { background: var(--accent-light); border: 1px solid rgba(6,182,212,0.4);  color: #cffafe; }
.alert-warn    { background: var(--yellow-light); border: 1px solid rgba(251,191,36,0.4); color: #fde68a; }

/* ── Status pills ───────────────────────────────────────────── */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-running { background: var(--yellow-light); color: #fde68a; }
.status-done    { background: var(--green-light);  color: #a7f3d0; }
.status-error   { background: var(--red-light);   color: #fecaca; }
.status-partial { background: var(--yellow-light); color: #fde68a; }
.status-manual,
.status-scheduled {
  background: var(--accent-light);
  color: #a5f3fc;
}

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

.status-running .dot { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Page header ────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: clamp(1.35rem, 2.5vw, 1.55rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 8px;
  max-width: 52ch;
  line-height: 1.5;
}

/* ── Modal ──────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; padding: 20px; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 500px;
  max-height: min(90vh, 720px);
  overflow-y: auto;
  box-shadow: var(--shadow), var(--shadow-card);
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Chart container ────────────────────────────────────────── */

.chart-wrap {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}

/* ── Tabs ───────────────────────────────────────────────────── */

.tabs { display: flex; gap: 4px; margin-bottom: 20px; }

.tab-btn {
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
  border: none;
  background: transparent;
  cursor: pointer;
}

.tab-btn:hover, .tab-btn.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Misc utilities ─────────────────────────────────────────── */

.text-muted   { color: var(--text-muted) !important; }
.text-green   { color: var(--green) !important; }
.text-red     { color: var(--red) !important; }
.text-accent  { color: var(--accent) !important; }

/* Nagłówek strony w widoku „wszystkie strony” /rankings — biały bez domyślnego koloru linku */
.site-title-link {
  color: #fff;
  text-decoration: none;
}
.site-title-link:hover,
.site-title-link:visited {
  color: #fff;
}
.site-title-link:hover {
  opacity: 0.92;
}

.fw-600       { font-weight: 600; }
.fw-700       { font-weight: 700; }
.font-mono    { font-family: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace; font-size: 0.86em; }
.gap-2        { gap: 8px; }
.flex         { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-3 { margin-bottom: 12px !important; }
.mb-4 { margin-bottom: 16px !important; }
.mt-4 { margin-top: 16px !important; }
.w-full { width: 100%; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.65; }
.empty-state-text { font-size: 0.9rem; color: var(--text-secondary); }

/* ── Login page ─────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  background-image: radial-gradient(ellipse at 30% 20%, rgba(6,182,212,0.08) 0%, transparent 60%),
                    radial-gradient(ellipse at 70% 80%, rgba(59,130,246,0.06) 0%, transparent 60%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 14px;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.login-sub {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
}

/* ── HTMX indicator ─────────────────────────────────────────── */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }

/* ── Tooltip ────────────────────────────────────────────────── */

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  margin-bottom: 5px;
  z-index: 200;
}

[data-tooltip]:hover::after { opacity: 1; }

/* ── Scrollbar ──────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Layout helpers (UX) ───────────────────────────────────── */

.dashboard-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 960px) {
  .dashboard-split { grid-template-columns: 1fr; }
}

.page-header--compact {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 16px;
  align-items: center;
}

.filter-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.filter-toolbar label {
  margin-bottom: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.filter-toolbar select {
  width: auto;
  min-width: 220px;
}

.kv-grid {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(18px, 3vw, 32px);
}

.kv-item-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.kv-item-value {
  margin-top: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.login-submit {
  justify-content: center;
  padding: 11px 18px;
  font-size: 0.95rem;
  margin-top: 10px;
  width: 100%;
}

.card--flush-inner .table-wrap {
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  box-shadow: none;
}

.card--toolbar {
  padding: 18px 22px !important;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-wrap { margin-left: 0; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0 16px; }
  .page-content { padding-left: 16px; padding-right: 16px; }
}
