/* ─────────────────────────────────────────────────────────────────────────────
   MARDELTUR · Admin panel
   Matches the public site's visual language: navy primary, blue accent,
   orange detail, off-white bg, Plus Jakarta Sans + DM Serif Display.
   ───────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800;900&family=DM+Serif+Display:ital@0;1&display=swap');

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

:root {
  --navy:        #172554;
  --navy-darker: #0e1a44;
  --blue:        #2563eb;
  --blue-soft:   rgba(37, 99, 235, 0.08);
  --orange:      #fc7303;
  --orange-soft: rgba(252, 115, 3, 0.10);
  --bg:          #FAFAF8;
  --card:        #ffffff;
  --text:        #0f172a;
  --muted:       #6b7280;
  --muted-soft:  #9ca3af;
  --line:        #e5e7eb;
  --line-soft:   #f1f5f9;
  --green-bg:    #ecfdf5;
  --green-fg:    #047857;
  --red-bg:      #fef2f2;
  --red-fg:      #b91c1c;

  --font-sans:   'Plus Jakarta Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif:  'DM Serif Display', Georgia, serif;
  --font-mono:   ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --shadow-card:  0 1px 3px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.04);
  --shadow-card-hover: 0 2px 4px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-modal: 0 24px 80px rgba(15, 23, 42, 0.20);
}

html, body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

a { color: inherit; }

/* ─── AUTH (login, change password) ─────────────────────────────────────────── */

body.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 80% 20%, rgba(37, 99, 235, 0.25) 0%, transparent 50%),
    radial-gradient(circle at 20% 80%, rgba(252, 115, 3, 0.10) 0%, transparent 50%),
    linear-gradient(135deg, var(--navy) 0%, var(--navy-darker) 100%);
}

body.auth .card {
  background: var(--card);
  width: 100%;
  max-width: 440px;
  border-radius: 16px;
  padding: 44px 40px 36px;
  box-shadow: var(--shadow-modal);
}

body.auth .card .brand.brand-auth {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  text-decoration: none;
}
body.auth .card .brand.brand-auth .brand-logo {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
body.auth .card .brand.brand-auth .brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
body.auth .card .brand.brand-auth .brand-text {
  font-family: var(--font-sans);
  font-weight: 900;
  font-size: 24px;
  letter-spacing: -0.5px;
  color: var(--orange);
  line-height: 1;
}

body.auth .card p.muted {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 28px;
}

body.auth .card label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 18px 0 8px;
}
body.auth .card label .req,
body.auth .card label .opt {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 6px;
  font-size: 11px;
}
body.auth .card label .req { color: var(--orange); }
body.auth .card label .opt { color: var(--muted-soft); }

body.auth .card input {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--text);
  transition: border-color 0.18s, box-shadow 0.18s;
}
body.auth .card input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

body.auth .card button {
  width: 100%;
  margin-top: 28px;
  padding: 15px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  font-family: inherit;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  text-transform: uppercase;
}
body.auth .card button:hover {
  background: var(--navy-darker);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(23, 37, 84, 0.25);
}
body.auth .card button:active { transform: translateY(0); }

body.auth .error {
  background: var(--red-bg);
  color: var(--red-fg);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  border: 1px solid #fecaca;
}

body.auth .link-muted {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
body.auth .link-muted:hover {
  color: var(--navy);
  border-bottom-color: var(--navy);
}

/* ─── DASHBOARD ─────────────────────────────────────────────────────────────── */

body.dash {
  min-height: 100vh;
  background: var(--bg);
}

/* Topbar */
.topbar {
  background: var(--navy);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.10);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}
.topbar .brand .brand-logo {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar .brand .brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.topbar .brand .brand-text {
  font-family: var(--font-sans);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: -0.3px;
  color: var(--orange);
  line-height: 1;
}

.topbar nav {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
.topbar .user {
  color: rgba(255, 255, 255, 0.55);
  margin-right: 4px;
}
.topbar .user strong {
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
  margin-left: 4px;
}
.topbar .link-muted {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.15s;
}
.topbar .link-muted:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.05);
}
/* Logout uses a POST form (CSRF-protected) but should look like the other nav items */
.topbar .logout-form { margin: 0; padding: 0; display: inline-flex; }
.topbar .logout-form button.link-muted {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  background: transparent;
}

/* Main content */
.content {
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 28px;
}

.page-head { margin-bottom: 28px; }
.page-head h2 {
  font-size: 34px;
  font-weight: 900;
  color: var(--navy);
  letter-spacing: -1px;
  margin-bottom: 6px;
}
.page-head p.muted {
  color: var(--muted);
  font-size: 14px;
}
.page-head p.muted strong { color: var(--navy); font-weight: 600; }

.flash {
  background: var(--green-bg);
  color: var(--green-fg);
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  border: 1px solid #a7f3d0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flash::before {
  content: '✓';
  font-weight: 800;
  font-size: 16px;
  width: 22px;
  height: 22px;
  background: #10b981;
  color: white;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ─── Channel tabs ─────────────────────────────────────────────────────────── */

.rate-tabs {
  display: inline-flex;
  background: var(--line-soft);
  padding: 4px;
  border-radius: 12px;
  gap: 2px;
  margin-bottom: 18px;
}
.rate-tab {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  padding: 10px 22px;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  letter-spacing: 0.2px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  line-height: 1.15;
}
.rate-tab .rate-tab-hint {
  font-size: 10px;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--muted-soft);
  text-transform: none;
  letter-spacing: 0;
}
.rate-tab:hover { color: var(--navy); }
.rate-tab.is-active {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}
.rate-tab.is-active .rate-tab-hint { color: var(--orange); }

.rate-panel { display: block; }
.rate-panel[hidden] { display: none; }

/* Rates form (card) — matches the public site's cotizaciones table */
.rates-form {
  background: var(--card);
  border-radius: 16px;
  padding: 0;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--line);
  overflow: hidden;
}

table.rates {
  width: 100%;
  border-collapse: collapse;
}
table.rates th, table.rates td {
  padding: 16px 24px;
  text-align: left;
  vertical-align: middle;
}
table.rates th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted-soft);
  background: rgba(15, 23, 42, 0.02);
  border-bottom: 1px solid var(--line);
}
table.rates th.num,
table.rates td.num {
  text-align: right;
}

table.rates tbody tr {
  transition: background 0.12s;
}
table.rates tbody tr:hover {
  background: rgba(37, 99, 235, 0.025);
}
table.rates tbody tr + tr td {
  border-top: 1px solid var(--line-soft);
}

/* Divisa cell: flag + code + name (mirrors site layout) */
table.rates td.divisa {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.flag {
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--line-soft);
}
.flag img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.35);
}
.ident {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ident .code {
  font-weight: 900;
  font-size: 18px;
  color: var(--navy);
  letter-spacing: -0.3px;
  line-height: 1.1;
}
.ident .name {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* Inputs */
table.rates input {
  width: 150px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  outline: none;
  font-family: var(--font-mono);
  background: #fff;
  text-align: right;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
table.rates input:hover {
  border-color: var(--muted-soft);
}
table.rates input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}
/* Sell input is the highlighted one (matches site's orange sell prices) */
table.rates input.sell {
  color: var(--orange);
  border-color: rgba(252, 115, 3, 0.35);
}
table.rates input.sell:hover {
  border-color: var(--orange);
}
table.rates input.sell:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 4px var(--orange-soft);
}

/* Visibility toggle (eye icon) — admin can hide a currency from a channel */
.eye-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.eye-toggle:hover    { background: var(--blue-soft); }
.eye-toggle:active   { transform: scale(0.92); }
.eye-toggle .eye-off { display: none; }
.eye-toggle.is-hidden { color: var(--muted-soft); }
.eye-toggle.is-hidden .eye-on  { display: none; }
.eye-toggle.is-hidden .eye-off { display: block; }
.eye-toggle.is-hidden:hover    { background: rgba(156, 163, 175, 0.12); color: var(--muted); }

/* Row hidden = entire row dimmed to signal it won't show on the channel */
table.rates tr.row-hidden td:not(:last-child) {
  opacity: 0.5;
}

/* Variation badge (matches site's green/red pill with icon) */
.change {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.change svg { flex-shrink: 0; }
.change.up   { color: var(--green-fg); background: var(--green-bg); }
.change.down { color: var(--red-fg);   background: var(--red-bg);   }

/* Actions row */
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0;
  padding: 20px 28px 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.actions button.primary {
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  font-family: inherit;
  padding: 14px 32px;
  border: 0;
  border-radius: 10px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  text-transform: uppercase;
}
.actions button.primary:hover {
  background: var(--navy-darker);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(23, 37, 84, 0.20);
}
.actions button.primary:active { transform: translateY(0); }
.actions .muted.small {
  color: var(--muted);
  font-size: 13px;
  max-width: 380px;
  text-align: right;
}

/* ─── Metrics card ──────────────────────────────────────────────────────────── */

.metrics-card {
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  margin-top: 28px;
  padding: 24px 28px 28px;
}
.metrics-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.metrics-head h3 {
  font-size: 22px;
  font-weight: 900;
  color: var(--navy);
  letter-spacing: -0.5px;
  margin-bottom: 2px;
}
.metrics-head p.muted { font-size: 13px; color: var(--muted); }

.metrics-filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.metrics-filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted-soft);
}
.metrics-filters input[type="date"] {
  padding: 9px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.metrics-filters input[type="date"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}
.metrics-presets {
  display: inline-flex;
  background: var(--line-soft);
  border-radius: 8px;
  padding: 3px;
}
.metrics-presets button {
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.metrics-presets button:hover { color: var(--navy); }
.metrics-presets button.on {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* Channel select (sits ABOVE the per-currency toggles in the chart card) */
.metrics-channel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
  border-top: 1px solid var(--line-soft);
}
.metrics-channel label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted-soft);
}
.metrics-channel select {
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  font-family: inherit;
  background: #fff;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.metrics-channel select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

.metrics-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.metrics-series {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.series-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--line-soft);
  border: 1px solid transparent;
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.series-chip:hover:not(:disabled) { color: var(--navy); }
.series-chip:disabled { opacity: 0.4; cursor: not-allowed; }
.series-chip.on {
  background: #fff;
  border-color: var(--line);
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}
.series-chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.metrics-mode {
  display: flex;
  gap: 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.metrics-mode label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.metrics-mode input[type="radio"] { accent-color: var(--blue); }

.metrics-chart-wrap {
  position: relative;
  width: 100%;
  height: 320px;
}
.metrics-chart-wrap canvas { width: 100% !important; height: 100% !important; }
.metrics-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
}
/* The HTML `hidden` attribute applies display:none, but our display:flex
   above overrides it (CSS wins over the UA stylesheet). Force the hidden
   state explicitly so toggling .hidden in JS actually works. */
.metrics-empty[hidden] { display: none; }

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

@media (max-width: 820px) {
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px 20px;
  }
  .topbar nav {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .topbar .user {
    width: 100%;
    margin-bottom: 4px;
  }

  .content { padding: 0 20px; margin: 24px auto; }
  .page-head h2 { font-size: 26px; }

  /* Collapse table to cards on mobile (4-column structure) */
  table.rates thead { display: none; }
  table.rates,
  table.rates tbody,
  table.rates tr,
  table.rates td { display: block; width: 100%; }
  table.rates tbody tr {
    padding: 18px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin: 12px;
    background: #fff;
  }
  table.rates tbody tr:hover { background: #fff; }
  table.rates tbody tr + tr td { border-top: 0; }

  table.rates td {
    padding: 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
  }

  /* Divisa cell stays as flex with flag + ident */
  table.rates td.divisa {
    padding: 0 0 14px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 6px;
    justify-content: flex-start;
  }
  table.rates td.num { text-align: right; }

  /* Add field labels via ::before on the numeric cells */
  table.rates td.num::before {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted-soft);
    text-transform: uppercase;
    letter-spacing: 1px;
  }
  table.rates td:nth-of-type(2)::before { content: 'Compra'; }
  table.rates td:nth-of-type(3)::before { content: 'Venta'; }
  table.rates td:nth-of-type(4)::before { content: 'Variación'; }
  table.rates td:nth-of-type(5)::before { content: 'Visible'; }

  table.rates input { width: 160px; }

  .actions {
    flex-direction: column;
    align-items: stretch;
    padding: 20px;
  }
  .actions button.primary { width: 100%; padding: 16px; }
  .actions .muted.small { text-align: center; max-width: none; }

  /* Metrics — stack on mobile */
  .metrics-card { padding: 20px 16px; }
  .metrics-head { flex-direction: column; gap: 14px; }
  .metrics-filters { width: 100%; }
  .metrics-filters label { flex: 1; }
  .metrics-filters input[type="date"] { width: 100%; }
  .metrics-presets { width: 100%; justify-content: space-between; }
  .metrics-presets button { flex: 1; }
  .metrics-toolbar { flex-direction: column; align-items: flex-start; }
  .metrics-chart-wrap { height: 260px; }
}
