/* ===============================
   Modern MIS UI — Drop-in Styles
   (FULLY UPDATED • Android vertical scroll fix + Table Alignment Fix)
   =============================== */

/* ---------- Theme tokens ---------- */
:root{
  --bg:#f7fafc;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#475569;

  --brand:#2563eb;
  --brand-700:#1d4ed8;
  --accent:#8b5cf6;

  --success:#16a34a;
  --warning:#f59e0b;
  --danger:#dc2626;

  --radius:14px;
  --radius-sm:10px;
  --shadow:0 10px 24px rgba(2,6,23,.08);
  --ring:0 0 0 4px rgba(37,99,235,.18);
  --sticky-offset:64px;
}

@media (prefers-color-scheme: dark){
  :root{
    --bg:#0b1220;
    --card:#0f172a;
    --text:#e5e7eb;
    --muted:#9ca3af;

    --brand:#60a5fa;
    --brand-700:#3b82f6;
    --accent:#a78bfa;

    --success:#34d399;
    --warning:#fbbf24;
    --danger:#f87171;

    --shadow:0 12px 28px rgba(0,0,0,.35);
    --ring:0 0 0 4px rgba(96,165,250,.22);
  }
}

/* ===== Base Layout ===== */
*{box-sizing:border-box}
html, body { height: 100%; }
html { scroll-behavior: smooth; }
body {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, -apple-system, "Noto Sans", "Segoe UI Emoji";
  background: var(--bg);
  margin: 0;
  padding: 0;
  color: var(--text);
  line-height: 1.45;
}

/* Sticky Header */
header.header {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  color: white;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.header .brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.15);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-meta h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing:.2px; }
.brand-meta small { display:block; margin-top:2px; opacity:.9; font-size:12px; }
header.header .user{
  font-size: 13px; opacity:.95;
  background: rgba(255,255,255,.12);
  padding: 6px 10px; border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}

.container {
  padding: 18px;
  max-width: 1280px;
  margin: auto;
}

/* ===== Filters ===== */
.filter-form {
  position: sticky; top: var(--sticky-offset); z-index: 40;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  border: 1px solid #00000012;
  transform: translateY(0);
  transition: transform .22s ease, opacity .2s ease, box-shadow .2s ease;
}
.filter-form.hide { transform: translateY(calc(-100% - 12px)); opacity: .02; box-shadow: none; pointer-events: none; }
.filter-form .row { display:flex; flex-direction:column; gap:6px; }
.filter-form label { font-size: 12px; color: var(--muted); }
.filter-form select,
.filter-form input[type="date"],
.filter-form button {
  padding: 10px 12px;
  border: 1px solid #00000022;
  border-radius: 10px;
  font-size: 14px;
  min-width: 160px;
  background: white;
  color: var(--text);
  outline: none;
  transition: box-shadow .15s ease, border-color .15s ease, transform .02s ease;
}
@media (prefers-color-scheme: dark){
  .filter-form select, .filter-form input[type="date"] { background:#0b1324; border-color:#ffffff22; }
}
.filter-form select:focus,
.filter-form input[type="date"]:focus { border-color: var(--brand); box-shadow: var(--ring); }

/* Buttons */
.btn-primary {
  background: var(--brand);
  color: white;
  border: none;
  cursor: pointer;
  transition: transform .02s ease, background .2s ease;
  min-height: 40px;
  border-radius: 10px;
}
.btn-primary:hover { background: var(--brand-700); }
.btn-primary:active{ transform: translateY(1px); }
.btn-secondary {
  background: #00000010;
  border: 1px solid #00000022;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 10px;
}
.btn-secondary:hover { background: #00000016; }

/* ===== Metric Cards ===== */
.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.metric-header h2 { margin:0; font-size:20px; }
.meta-updated { color: var(--muted); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.metric-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 14px 14px;
  box-shadow: var(--shadow);
  text-align: center;
  border: 1px solid #00000010;
  transition: transform 120ms ease, box-shadow .2s ease;
}
.metric-card::before{
  content:"";
  position:absolute; left:0; right:0; top:0; height:4px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}
.metric-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,.12); }

.metric-value {
  font-size: 28px;
  color: var(--brand-700);
  font-weight: 800;
  line-height: 1.1;
}
@media (prefers-color-scheme: dark){ .metric-value{ color: var(--brand); } }

.metric-name {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  font-weight: 600;
  letter-spacing:.2px;
}
.metric-actions { margin-top: 10px; display:flex; justify-content:center; gap:8px; }
.metric-actions button {
  background: var(--brand);
  color: white;
  border: none;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  box-shadow: 0 2px 10px rgba(25,118,210,.25);
  transition: transform .02s ease, background .2s ease;
}
.metric-actions button:hover { background: var(--brand-700); }
.metric-actions button:active{ transform: translateY(1px); }

/* ===== Sections & Tables ===== */
.section {
  background: var(--card);
  border-radius: var(--radius);
  margin-top: 22px;
  box-shadow: var(--shadow);
  padding: 14px;
  border: 1px solid #00000012;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  gap: 8px;
}
.section-title { display: flex; align-items: center; gap: 10px; }
.section-title h3 { color: var(--brand); margin: 0; font-size: 18px; }
.data-badge {
  background: #e8f0ff; color: var(--brand-700);
  font-weight: 600; font-size: 12px; padding: 4px 8px; border-radius: 999px;
}
@media (prefers-color-scheme: dark){
  .data-badge{ background:#13345d; color:#cfe2ff; }
}
.section-actions button {
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  margin-left: 5px;
  box-shadow: 0 2px 10px rgba(25,118,210,.25);
}
.section-actions .btn-download { background: var(--brand-700); }
.section-actions button:hover { opacity: .92; }

/* ===== Responsive Table (Alignment Fixed) ===== */
.table-container {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  border-radius: 10px;
  border: 1px solid #00000012;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
}
.table-container table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; /* fix column widths */
  font-size: 13px;
  min-width: 760px;
  background: transparent;
}
.table-container th,
.table-container td {
  padding: 10px 12px;
  text-align: center;
  vertical-align: middle;
  border-bottom: 1px solid #00000012;
  white-space: nowrap;
}
.table-container th {
  background: linear-gradient(180deg, var(--brand), var(--brand-700));
  color: #fff;
  font-weight: 600;
  text-transform: lowercase;
}
.table-container td:first-child,
.table-container th:first-child {
  text-align: left;
}
.table-container td[data-num="1"] {
  text-align: center !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}
.table-container tbody tr:nth-child(even) { background: #00000006; }
.table-container tbody tr:hover td { background: #00000008; }
@media (prefers-color-scheme: dark){
  .table-container tbody tr:nth-child(even){ background: #ffffff05; }
  .table-container tbody tr:hover td { background: #ffffff08; }
}
.table-container::-webkit-scrollbar{ height:10px; width:10px }
.table-container::-webkit-scrollbar-thumb{ background:#00000025; border-radius:999px; }
.table-container::-webkit-scrollbar-track{ background:transparent }

/* ===== Misc ===== */
.nodata, .nodata-table {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 14px;
}

/* Back-to-top floating button */
.to-top{
  position: fixed; right: 14px; bottom: 20px; z-index: 60;
  width: 42px; height: 42px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--brand);
  color: #fff; border: none; box-shadow: var(--shadow);
  cursor: pointer; opacity: 0; transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease, background .2s ease;
}
.to-top.show{ opacity: 1; transform: translateY(0); }
.to-top:hover{ background: var(--brand-700); }

/* ===== Mobile Tweaks ===== */
@media (max-width: 768px) {
  .container{ padding: 14px }
  .filter-form { align-items: stretch; gap: 10px; }
  .filter-form select,
  .filter-form input[type="date"]{ min-width: 100%; }
  .metric-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .metrics-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
  .table-container table { min-width: 640px; font-size: 12px; }
  .table-container th, .table-container td { padding: 8px 10px; }
  header.header { padding: 10px 14px; }
  .brand-logo { width: 32px; height: 32px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce){
  .metric-card, .btn-primary, .metric-actions button, .filter-form, .to-top { transition: none; }
}
