/* ==========================================================================
   Kursy walut NBP — arkusz stylów
   Prosty, nowoczesny interfejs narzędziowy: jasne tło, karty, miękkie cienie.
   ========================================================================== */

:root {
  --bg: #f4f6fa;
  --bg-gradient: radial-gradient(1200px 600px at 50% -200px, #e6edfb 0%, #f4f6fa 60%);
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #cbd5e1;

  --text: #1a2233;
  --text-soft: #5a6779;
  --text-muted: #8792a5;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;

  --success: #0f7a4d;
  --success-soft: #e8f7f0;
  --warning: #92610b;
  --warning-soft: #fdf5e3;
  --danger: #b42318;
  --danger-soft: #fdeceb;

  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);

  --max-width: 1080px;
}

/* ---------- Reset / podstawy ---------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }

.wrap {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: 20px;
}

/* ---------- Nagłówek ---------- */

.site-header {
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-block: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  font-size: 26px;
  line-height: 1;
  background: var(--primary-soft);
  border: 1px solid #dbe6ff;
  border-radius: var(--radius-md);
  padding: 8px 10px;
  flex: none;
}

.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1.2rem; }

.subtitle {
  color: var(--text-soft);
  font-size: .85rem;
  margin-top: 2px;
}

/* Przełącznik języka */
.lang-switch {
  display: inline-flex;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  flex: none;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}

/* Okrągła flaga w przełączniku języka */
.flag {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(16, 24, 40, .12);
  opacity: .55;
  transition: opacity .15s ease;
}

.lang-btn:hover .flag,
.lang-btn.is-active .flag { opacity: 1; }

.lang-btn:hover { color: var(--text); }

.lang-btn.is-active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

/* ---------- Układ główny ---------- */

.main-content {
  flex: 1 0 auto;
  padding-block: 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.card-head { margin-bottom: 18px; }
.card-head h2 { font-size: 1.1rem; }

.card-desc {
  color: var(--text-soft);
  font-size: .9rem;
  margin-top: 4px;
}

/* ---------- Formularze ---------- */

/* 4 pola o równej szerokości + wąska kolumna na kompaktowy przycisk akcji */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 14px;
  align-items: start;
}

.form-grid-export { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field-wide { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-soft);
}

/* Stała wysokość wszystkich kontrolek — pole typu date bywa o kilka px wyższe
   od pozostałych, co rozjeżdżałoby wyrównanie w wierszu formularza. */
input[type="date"],
input[type="number"],
input[type="search"],
select {
  width: 100%;
  font: inherit;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 44px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235a6779' d='M1.4 0 6 4.6 10.6 0 12 1.4 6 7.4 0 1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .18);
}

button:focus-visible { outline: 2px solid transparent; }

input:disabled,
select:disabled { background: var(--surface-soft); color: var(--text-muted); cursor: not-allowed; }

.hint {
  font-size: .76rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Pole wynikowe (tylko do odczytu) wyglądem dopasowane do pól formularza */
.value-box {
  display: flex;
  align-items: center;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #cceadd;
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  color: var(--success);
  font-size: .95rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Kolumna z przyciskiem: przycisk tylko na szerokość tekstu,
   wyrównany dolną krawędzią do pozostałych pól w wierszu. */
.field-actions {
  align-self: end;
  align-items: flex-start;
}

/* ---------- Przyciski ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 11px 16px;
  min-height: 42px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .05s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-soft);
}

.btn-ghost:hover:not(:disabled) { background: var(--surface-soft); color: var(--text); }

.btn-small { font-size: .8rem; padding: 7px 12px; min-height: 34px; }

.btn-compact { font-size: .88rem; padding: 8px 16px; min-height: 38px; }

.btn:disabled { opacity: .6; cursor: not-allowed; }

/* Spinner w przycisku (widoczny tylko w stanie ładowania) */
.btn-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}

.btn.is-loading .btn-spinner { display: inline-block; }

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

@media (prefers-reduced-motion: reduce) {
  .btn-spinner { animation-duration: 2s; }
  * { scroll-behavior: auto; }
}

/* ---------- Komunikaty statusu ---------- */

.status {
  display: none;
  margin-top: 16px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-size: .88rem;
  border: 1px solid transparent;
}

.status.is-visible { display: block; }

.status.is-info    { background: var(--primary-soft); border-color: #dbe6ff; color: var(--primary-dark); }
.status.is-loading { background: var(--primary-soft); border-color: #dbe6ff; color: var(--primary-dark); }
.status.is-success { background: var(--success-soft); border-color: #cceadd; color: var(--success); }
.status.is-warning { background: var(--warning-soft); border-color: #f3e2bd; color: var(--warning); }
.status.is-error   { background: var(--danger-soft);  border-color: #f7d4d1; color: var(--danger); }

.status ul { margin: 6px 0 0; padding-left: 20px; }
.status li { margin-top: 2px; }

/* ---------- Karty wyników ---------- */

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.result-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.result-box-accent { background: var(--primary-soft); border-color: #dbe6ff; }

.result-label {
  font-size: .76rem;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.result-value {
  font-size: 1.32rem;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.result-box-accent .result-value { color: var(--primary-dark); }

.result-meta {
  font-size: .76rem;
  color: var(--text-muted);
  min-height: 1em;
}

/* ---------- Historia / tabela ---------- */

.history-block {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.history-head h3 { font-size: .98rem; }

.table-scroll {
  margin-top: 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  min-width: 380px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th {
  background: var(--surface-soft);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-soft);
  font-weight: 650;
}

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #fbfcfe; }

.data-table td.num { font-variant-numeric: tabular-nums; font-weight: 600; }

.code-badge {
  display: inline-block;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 1px solid #dbe6ff;
  border-radius: 6px;
  font-size: .74rem;
  font-weight: 700;
  padding: 1px 6px;
  margin-right: 6px;
}

.currency-name { color: var(--text-soft); font-size: .84rem; }

.empty-row td {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  white-space: normal;
  padding-block: 18px;
}

/* ---------- Wybór wielu walut ---------- */

.picker-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.picker-toolbar input[type="search"] { flex: 1 1 220px; min-width: 0; }

.currency-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 4px;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--surface-soft);
}

.picker-placeholder {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: .86rem;
  padding: 8px;
  font-style: italic;
}

.currency-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .86rem;
  transition: background-color .12s ease;
  min-width: 0;
}

.currency-option:hover { background: #eef3fd; }

.currency-option input { accent-color: var(--primary); width: 16px; height: 16px; flex: none; cursor: pointer; }

.currency-option .opt-code { font-weight: 700; flex: none; }

.currency-option .opt-name {
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.currency-option.is-hidden { display: none; }

/* ---------- Szybkie zakresy ---------- */

.quick-ranges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.quick-label { font-size: .8rem; color: var(--text-soft); font-weight: 600; }

.chip {
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-soft);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.chip:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary-dark); border-color: #c7d9ff; }
.chip:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Pasek postępu ---------- */

.progress { margin-top: 16px; display: flex; align-items: center; gap: 12px; }

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .2s ease;
}

.progress-text {
  font-size: .8rem;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Stopka ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, .7);
  padding-block: 18px;
  margin-top: auto;
}

.site-footer p { font-size: .82rem; color: var(--text-soft); }
.footer-small { font-size: .76rem; color: var(--text-muted); margin-top: 3px; }

/* ---------- RWD ---------- */

@media (max-width: 900px) {
  .form-grid,
  .form-grid-export { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .wrap { padding-inline: 14px; }
  .main-content { padding-block: 20px 28px; gap: 16px; }
  .card { padding: 16px; border-radius: 14px; }

  .header-inner { padding-block: 12px; }
  .brand-text h1 { font-size: 1.05rem; }
  .subtitle { font-size: .78rem; }
  .lang-switch { width: 100%; justify-content: center; }
  .lang-btn { flex: 1; }

  .form-grid,
  .form-grid-export,
  .results-grid { grid-template-columns: minmax(0, 1fr); }

  .field-actions { align-self: start; }
  .currency-picker { max-height: 200px; grid-template-columns: minmax(0, 1fr); }
  .result-value { font-size: 1.18rem; }
}
