/*******************************
 * Dashboard UI — Responsive CSS
 *******************************/

/* =========
   Variables
   ========= */
:root {
  /* layout scales */
  --grid-gap: clamp(10px, 2vw, 24px);
  --col-min: clamp(260px, 30vw, 400px);
  --card-min-h: clamp(260px, 40vw, 420px);
  --chart-aspect: 16/9;

  /* colors / shadows */
  --bg: #ffffff;
  --bg-soft: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --stroke: rgba(0,0,0,0.06);
  --shadow: 0 6px 20px rgba(0,0,0,.08);

  --brand: #111827;
  --brand-cta: #111827;
  --bar: #3b82f6;
}

/* fluid root type size */
html { font-size: clamp(14px, 1.6vw, 16px); }

/* ======
   Basics
   ====== */
.bg-grid { background: var(--bg-soft); }
.container { max-width: clamp(320px, 92vw, 1200px); margin: auto; padding-inline: clamp(10px, 2vw, 24px); }
.title { font-size: clamp(1.4rem, 2.2vw, 2.2rem); text-align: center; margin-bottom: .5rem; color: var(--text); }
.meta { text-align: right; margin-bottom: 10px; }
.muted { color: var(--muted); }

/* ====================
   Grid holding cards
   ==================== */
.dashboard-grid{
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(min(100%, var(--col-min)), 1fr)
  );
  gap: var(--grid-gap);
  align-items: stretch;
  container-type: inline-size;
}

/* ======
   Cards
   ====== */
.card {
  display: flex;
  flex-direction: column;
  min-height: var(--card-min-h);
  border: 1px solid var(--stroke);
  background: var(--bg);
  border-radius: 20px;
  box-shadow: none;
  overflow: hidden;
}
.card.flat { box-shadow: none; }
#card-top-countries,
#card-source { box-shadow: none; }

.card-header{
  display:flex; justify-content:space-between; align-items:end;
  padding:10px 10px 10px 10px;
}
.card-title{ font-size:1.1rem; color:var(--text); margin:0; }
.stats{ text-align:right; }
.counter{ font-weight:800; font-size:1.25rem; color:var(--text); }

/* ===========
   Chart areas
   =========== */
.chart {
  flex: 1 1 auto;
  width: 100%;
  min-height: 300px;
  display: block;
  padding: 0;
  margin: 0;
  aspect-ratio: var(--chart-aspect);
}
.chart svg{ width:100% !important; height:auto !important; display:block; }
.chart-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 2px 9px;
}
.empty{ text-align:center; padding:18px; color:var(--muted); }

/* =========================
   Filters (auto-adjusting)
   ========================= */
.filters{ display:flex; flex-direction:column; gap: clamp(8px, 1.6vw, 12px); padding:6px 20px 12px 20px; }

/* Desktop: make Actions column wide enough for stacked buttons */
.filters-grid{
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr) minmax(140px, 0.8fr);
  grid-template-areas:
    "from to actions"
    "country country actions";
  gap: 10px;
  align-items: stretch;
  grid-auto-rows: 1fr;
}

/* Map fields to areas (DOM order: From, To, Country, Actions) */
.filters .field{ display:flex; flex-direction:column; gap:6px; min-width:0; height:100%; }
.filters .field:nth-child(1){ grid-area: from; }
.filters .field:nth-child(2){ grid-area: to; }
.filters .field:nth-child(3){ grid-area: country; }

/* Actions: STACK buttons vertically (always) */
.filters .field.actions{
  grid-area: actions;
  display:flex;
  flex-direction: column;     /* stack */
  gap:8px;
  align-items: stretch;       /* full width */
  justify-content: flex-start;
}

.field-label{ font-size:12px; color:var(--muted); }

/* Inputs */
.input{
  border:1px solid var(--stroke); border-radius:10px; padding:8px 10px; font-size:13px;
  background: var(--bg); color: var(--text);
}
.filters .field .input,
.filters .field select,
.filters .field input[type="date"]{
  width: 100%;
  height: 40px;
  min-width: 0;
  flex: 1 1 auto;
}

/* ==== From / To bigger ==== */
.filters .field:nth-child(1) .input,
.filters .field:nth-child(2) .input,
.filters .field:nth-child(1) input[type="date"],
.filters .field:nth-child(2) input[type="date"] {
  height: 48px; /* was 40px */
  font-size: 15px;
  padding: 0 14px;
}

/* Buttons */
.btn{
  padding:4px 12px; border-radius:12px; border:1px solid var(--stroke); background:var(--bg);
  box-shadow:0 2px 10px rgba(0,0,0,.05); cursor:pointer; font-size:13px; color:var(--text);
}
.btn.primary{ background:var(--brand-cta); color:#fff; border-color:var(--brand-cta); }
.btn:hover{ box-shadow:0 4px 16px rgba(0,0,0,.08); }

/* ==== Clear / Apply stacked & compact ==== */
.filters .field.actions .btn{
  width: 100%;              /* full column width */
  height: 40px;             /* compact but comfy */
  padding: 6px 10px;
  font-size: 13px;
  min-width: 0;             /* prevent overflow */
}

/* Quick pills */
.filters-row{ display:flex; gap:12px; align-items:center; justify-content:space-between; flex-wrap:wrap; }
.quick-pills{ display:flex; gap:8px; flex-wrap:wrap; }
.pill{
  border:1px solid var(--stroke); background:var(--bg);
  padding:6px 10px; border-radius:999px; font-size:12px; cursor:pointer;
}
.pill:hover{ background:rgba(0,0,0,.04); }

/* Dates iOS polish */
@supports (-webkit-touch-callout: none) {
  .filters input[type="date"] { padding-block: 0; }
  .filters input[type="date"]::-webkit-date-and-time-value {
    height: 100%; display: flex; align-items: center;
  }
  .filters input[type="date"]::-webkit-calendar-picker-indicator { margin-right: 4px; }
}

/* ==========
   Breakpoints
   ========== */

/* Mid widths: collapse to 2 equal columns; actions drops below (still stacked) */
@media (max-width: 980px){
  .filters-grid{
    grid-template-columns: repeat(2, minmax(0,1fr));
    grid-template-areas:
      "from to"
      "country country"
      "actions actions";
  }
}

/* Mobile: single column, large tappable buttons; chart & card tweaks */
@media (max-width: 640px){
  .filters{
    padding: 8px 12px 10px 12px;
    gap: 8px;
  }
  .field-label{ font-size: 11px; margin-bottom: 3px; }

  .input,
  .filters input[type="date"]{ height: 44px; font-size: 15px; }

  .filters-grid{
    grid-template-columns: 1fr;
    grid-template-areas:
      "from"
      "to"
      "country"
      "actions";
    gap: 10px;
  }

  .filters .field.actions{
    flex-direction: column;   /* keep stacked */
    align-items: stretch;
  }

  .filters .field.actions .btn{
    height: 44px;             /* bigger tap target on phones */
    font-size: 14px;
  }

  /* Cards & headers */
  .card{ min-height: 240px; }
  .card-header{ padding: 10px 12px 4px 12px; gap: 6px; }
  .card-title{ font-size: 1rem; }
  .counter{ font-size: 1.05rem; }

  /* Charts: relax forced ratio on phones */
  .chart-wrap{ padding: 6px 8px 2px 8px; }
  .chart{ min-height: auto; aspect-ratio: auto; width: 100%; display: block; }
  .chart svg{ width: 100% !important; height: 100% !important; display: block; }

  /* Tooltip readability */
  .bubble-tip{ max-width: 92vw; font-size: 11px; }
}

/* ==========
   Cards tweak
   ========== */
.card { overflow: visible; }
#card-country-new .chart-wrap, #card-source .chart-wrap {
  max-height: 480px;
  overflow: auto;
}

/* =============
   Accessibility
   ============= */
@media (prefers-reduced-motion: reduce){
  * { animation: none !important; transition: none !important; }
}
