/* Office Dashboard — Berry-inspired light theme, mobile-first responsive.
   Tokens sampled from Berry Free React Admin Template (default theme):
   primary #2196f3, secondary #673ab7, success #00c853, error #f44336,
   grey50 #f8fafc, grey100 #eef2f6, divider #e3e8ef, radius 8px, Roboto. */
:root {
  --bg: #f8fafc;
  --paper: #ffffff;
  --divider: #e3e8ef;
  --txt: #121926;
  --txt2: #364152;
  --muted: #697586;
  --primary: #2196f3;
  --primary-dark: #1e88e5;
  --primary-light: #e3f2fd;
  --secondary: #673ab7;
  --secondary-dark: #5e35b1;
  --secondary-light: #ede7f6;
  --success: #00a651;
  --success-light: #d9f5e5;
  --error: #f44336;
  --error-dark: #c62828;
  --error-light: #fdecea;
  --warn: #b7791f;
  --warn-light: #fff8e1;
  --health: #2196f3;
  --health-bg: #e3f2fd;
  --fishery: #673ab7;
  --fishery-bg: #ede7f6;
  --finance: #00a651;
  --finance-bg: #d9f5e5;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(18, 25, 38, 0.08);
  --shadow-lg: 0 4px 16px rgba(18, 25, 38, 0.12);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--txt);
  overflow-x: hidden;
}

/* ---------- header (Berry app-bar: white, sticky, soft shadow) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--divider);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: var(--radius); flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  box-shadow: var(--shadow);
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; color: var(--txt); }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.status-wrap { display: flex; align-items: center; gap: 8px; }
.pill { padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--divider); color: var(--txt2); }
.pill.live { background: var(--success-light); color: var(--success); }
.pill.down { background: var(--error-light); color: var(--error-dark); }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- department tabs (3 equal tabs, Berry tab style) ---------- */
.tabs {
  display: flex; gap: 8px;
  padding: 12px 20px 0;
  max-width: 1200px; margin: 0 auto;
  position: sticky; top: 69px; z-index: 40;
  background: var(--bg);
}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 8px;
  background: var(--paper); color: var(--txt2);
  border: 1px solid var(--divider); border-bottom: 3px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 14px; font-weight: 500; cursor: pointer;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.tab .ticon { font-size: 18px; line-height: 1; }
.tab .tlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.active { color: var(--txt); font-weight: 700; background: var(--paper); }
.tab[data-dept="health"].active { border-bottom-color: var(--health); }
.tab[data-dept="fishery"].active { border-bottom-color: var(--fishery); }
.tab[data-dept="finance"].active { border-bottom-color: var(--finance); }
.count { border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 500; color: #fff; background: #90a4ae; flex: none; }
.tab[data-dept="health"] .count { background: var(--health); }
.tab[data-dept="fishery"] .count { background: var(--fishery); }
.tab[data-dept="finance"] .count { background: var(--finance); }

/* ---------- layout ---------- */
#panels { padding: 0 20px 30px; max-width: 1200px; margin: 0 auto; }
.panel { display: none; padding-top: 14px; }
.panel.active { display: block; }
.grid2 { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- Berry cards ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.card.accent-health { border-top: 3px solid var(--health); }
.card.accent-fishery { border-top: 3px solid var(--fishery); }
.card.accent-finance { border-top: 3px solid var(--finance); }

/* ---------- Berry stat mini-cards (tinted like Berry dashboard widgets) ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  border-radius: var(--radius); padding: 12px 10px; text-align: center;
  border: 1px solid var(--divider); background: var(--paper); box-shadow: var(--shadow);
}
.stat .num { font-size: 20px; font-weight: 700; line-height: 1.2; }
.stat .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.dept-health .stat.tint { background: var(--health-bg); border-color: #bbdefb; }
.dept-health .stat.tint .num { color: #1565c0; }
.dept-fishery .stat.tint { background: var(--fishery-bg); border-color: #d1c4e9; }
.dept-fishery .stat.tint .num { color: var(--fishery); }
.dept-finance .stat.tint { background: var(--finance-bg); border-color: #a9e8c6; }
.dept-finance .stat.tint .num { color: var(--success); }

/* ---------- buttons & inputs (44px+ touch targets) ---------- */
.btn {
  background: var(--primary); color: #fff; border: none;
  border-radius: var(--radius); padding: 12px 16px; min-height: 44px;
  font-weight: 500; font-size: 14px; cursor: pointer; box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn.ghost { background: transparent; box-shadow: none; }
.dept-health .btn.ghost { color: var(--primary-dark); border: 1px solid var(--primary); }
.dept-fishery .btn.ghost { color: var(--secondary); border: 1px solid var(--secondary); }
.dept-finance .btn.ghost { color: var(--success); border: 1px solid var(--success); }
.dept-fishery .btn.solid { background: var(--secondary); }
.dept-finance .btn.solid { background: var(--success); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; white-space: nowrap; }
input[type="file"] {
  width: 100%; margin: 8px 0; padding: 10px;
  border: 1.5px dashed #b0bec5; border-radius: var(--radius);
  background: var(--bg); color: var(--txt2); font-size: 13px; min-height: 44px;
}
input[type="search"] {
  width: 100%; padding: 11px 12px; min-height: 44px;
  border-radius: var(--radius); border: 1px solid var(--divider);
  background: var(--bg); color: var(--txt); font-size: 14px;
}
input[type="search"]:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- messages (Berry Alert tints) ---------- */
.msg { border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; font-size: 13px; display: none; white-space: pre-wrap; border: 1px solid transparent; }
.msg.show { display: block; }
.msg.error { background: var(--error-light); color: var(--error-dark); border-color: var(--error); }
.msg.ok { background: var(--success-light); color: #14703c; border-color: var(--success); }

/* ---------- totals chips (Berry Chip) ---------- */
.totals { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.chip { background: var(--bg); border: 1px solid var(--divider); border-radius: 999px; padding: 6px 12px; font-size: 12px; color: var(--txt2); }

/* ---------- table (desktop) ---------- */
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--divider); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--divider); text-align: left; }
th {
  position: sticky; top: 0; background: var(--bg); color: var(--txt2);
  cursor: pointer; user-select: none; white-space: nowrap; font-weight: 600; z-index: 1;
}
td { white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; color: var(--txt2); }
tbody tr:nth-child(even) td { background: #fbfcfe; }
tbody tr:hover td { background: var(--primary-light); }
.dept-fishery tbody tr:hover td { background: var(--secondary-light); }
.dept-finance tbody tr:hover td { background: var(--finance-bg); }

canvas.chart { width: 100%; height: 200px; display: block; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-box { background: var(--bg); border: 1px solid var(--divider); border-radius: var(--radius); padding: 10px 10px 6px; }
.chart-title { font-size: 12px; font-weight: 600; color: var(--txt2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.foot { padding: 14px 20px 30px; max-width: 1200px; margin: 0 auto; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.sort-mobile { display: none; }

/* ---------- mobile (≤640px): Berry cards, table becomes stacked record cards ---------- */
@media (max-width: 640px) {
  .topbar { padding: 10px 12px; top: 0; }
  .topbar h1 { font-size: 17px; }
  .avatar { width: 38px; height: 38px; font-size: 19px; }
  #lastRefresh { display: none; }
  .tabs { padding: 10px 12px 0; top: 63px; }
  .tab { font-size: 13px; min-height: 52px; }
  .tab .tlabel { display: none; }
  .tab .ticon { font-size: 20px; }
  .tab .count { font-size: 11px; }
  #panels { padding: 0 12px 24px; }
  .card { padding: 14px 12px; }
  .btn-row .btn { flex: 1 1 100%; }
  .stat .num { font-size: 17px; }
  .sort-mobile { display: block; margin-top: 8px; }
  .sort-mobile label { font-size: 12px; color: var(--muted); display: block; }
  .sort-mobile select {
    width: 100%; min-height: 44px; margin-top: 4px; padding: 10px 12px;
    border-radius: var(--radius); border: 1px solid var(--divider);
    background: var(--paper); color: var(--txt); font-size: 14px;
  }

  /* table → cards */
  .table-wrap { border: none; overflow: visible; max-height: none; background: transparent; }
  .table-wrap table, .table-wrap tbody { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    display: block; background: var(--paper);
    border: 1px solid var(--divider); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 10px; padding: 6px 0;
  }
  .table-wrap td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    white-space: normal; max-width: none; overflow: visible;
    border-bottom: 1px solid var(--divider); padding: 8px 12px;
    font-size: 13px;
  }
  .table-wrap td:last-child { border-bottom: none; }
  .table-wrap td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--muted); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.4px; flex: none; max-width: 40%;
  }
  .table-wrap td > span { text-align: right; overflow-wrap: anywhere; }
  .table-wrap tr.empty-row td::before { content: none; }
  canvas.chart { height: 180px; }
}
