/* DIVY POWER webapp theme: shared tokens + components (UI, Brand & Color Guidelines, Nov 2026).
   Keep this file the same across Divy webapps (AMC, Partner, Workspace).
   v3: left-sidebar layout (replaces the top nav). */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
  /* Brand */
  --divy-navy: #14317D;
  --divy-navy-dark: #0F2459;
  --divy-orange: #E87038;          /* sampled from the logo (sun + swoosh) */
  --divy-green: #1E8E3E;
  --divy-green-text: #187334;
  --sidebar-bg: #0F1E3D;

  /* Action & status */
  --primary: #1F5FBF;
  --primary-hover: #174C9C;
  --warning: #B54708;
  --danger: #B42318;

  /* Neutrals */
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-muted: #EEF1F5;
  --border: #DDE1E7;
  --border-input: #C6CCD6;
  --text: #1D2330;
  --text-muted: #6B7484;

  /* Badges: background / text */
  --badge-success-bg: #E7F4EC; --badge-success-fg: #187334;
  --badge-warning-bg: #FEF0DC; --badge-warning-fg: #B54708;
  --badge-danger-bg: #FEE4E2; --badge-danger-fg: #B42318;
  --badge-info-bg: #E6ECF8; --badge-info-fg: #14317D;
  --badge-neutral-bg: #EEF1F5; --badge-neutral-fg: #4A5260;
  --badge-gold-bg: #FDEBC8; --badge-gold-fg: #7A4A00;

  /* Type */
  --font: "Poppins", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --fs-title: 22px; --fs-section: 18px; --fs-kpi: 28px;
  --fs-body: 14px; --fs-label: 13px; --fs-meta: 12px;

  /* Shape & space */
  --radius-card: 8px; --radius-control: 6px; --radius-pill: 999px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --nav-height: 56px; --sidebar-w: 240px; --container: 1320px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-body); line-height: 20px; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: var(--font); }

/* ---------- Shell: left sidebar + topbar ---------- */
.shell { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; }

.sidebar { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--sidebar-bg); color: #fff;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 30; display: flex; flex-direction: column; padding-bottom: var(--space-4); }
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); height: var(--nav-height); padding: 0 var(--space-4);
  font-size: 17px; font-weight: 700; color: #fff; white-space: nowrap; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: var(--space-3); }
.sidebar-brand:hover { text-decoration: none; }
.nav-logo { height: 32px; background: #fff; border-radius: var(--radius-control); padding: 3px 6px; display: block; }
.sidebar-menu { display: flex; flex-direction: column; }
.sidebar-menu a { display: flex; align-items: center; height: 42px; margin: 2px var(--space-3); padding: 0 var(--space-4);
  border-radius: var(--radius-control); color: rgba(255,255,255,.82); font-weight: 500; white-space: nowrap; }
.sidebar-menu a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-menu a.active { background: var(--divy-orange); color: var(--sidebar-bg); font-weight: 600; } /* navy on orange = 5.7:1 */
.sidebar-foot { margin-top: auto; padding: var(--space-4) var(--space-4) 0; font-size: var(--fs-meta); line-height: 16px; color: rgba(255,255,255,.55); }

.topbar { position: sticky; top: 0; z-index: 20; height: var(--nav-height); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: 0 var(--space-5); }
.topbar-title { color: var(--text-muted); font-size: var(--fs-label); font-weight: 500; }
.topbar-status { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; white-space: nowrap; }
.topbar-status .badge { font-size: var(--fs-meta); }
.topbar-user { display: flex; align-items: center; gap: var(--space-4); margin-left: var(--space-4); font-size: var(--fs-label); font-weight: 500; white-space: nowrap; }
.topbar-user a { font-weight: 500; }
.nav-toggle { display: none; background: none; border: 0; color: var(--text); font-size: 24px; height: var(--nav-height); padding: 0 var(--space-2); cursor: pointer; }
.nav-toggle:hover { background: var(--bg); }
.sidebar-backdrop { display: none; }

/* ---------- Page ---------- */
main { max-width: var(--container); margin: 0 auto; padding: var(--space-5); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
h1 { font-size: var(--fs-title); line-height: 30px; font-weight: 600; margin: 0; }
h2 { font-size: var(--fs-section); line-height: 26px; font-weight: 600; margin: var(--space-6) 0 var(--space-3); }
.meta, .muted { color: var(--text-muted); font-size: var(--fs-meta); line-height: 16px; }
p.meta { margin: 0 0 var(--space-2); }
.flag { color: var(--warning); font-weight: 600; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 20px; margin-bottom: var(--space-4); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-4); }
.kpi { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--space-4); color: var(--text); }
.kpi:hover { border-color: var(--primary); text-decoration: none; }
.kpi b { display: block; font-size: var(--fs-kpi); line-height: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi span { display: block; font-size: var(--fs-label); color: var(--text-muted); }
.kpi.zero b { color: var(--text-muted); }
.kpi.warn b { color: var(--warning); }
.kpi.hot b { box-shadow: inset 0 -3px 0 var(--divy-orange); display: inline-block; }

/* ---------- Forms ---------- */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); align-items: end; }
.grid .wide { grid-column: 1 / -1; }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
.grid > .actions { grid-column: 1 / -1; margin-top: 0; }
label { display: block; font-size: var(--fs-label); line-height: 18px; font-weight: 500; margin-bottom: var(--space-1); }
label.check { display: flex; align-items: center; gap: var(--space-2); min-height: 40px; margin: 0; }
input, select, textarea { width: 100%; height: 40px; padding: 0 var(--space-3); border: 1px solid var(--border-input);
  border-radius: var(--radius-control); font: inherit; color: var(--text); background: #fff; }
textarea { height: auto; padding: var(--space-2) var(--space-3); }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; }
input[type=file] { height: auto; padding: var(--space-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,95,191,.2); }
td input, td select { min-width: 120px; }
form.inline { display: inline; }

/* ---------- Buttons ---------- */
button, .btn { display: inline-flex; align-items: center; justify-content: center; height: 40px; padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-control); font: inherit; font-weight: 500; cursor: pointer;
  background: var(--primary); color: #fff; white-space: nowrap; }
button:hover, .btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: #fff; border-color: var(--border-input); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-success { background: var(--divy-green-text); }
.btn-success:hover { background: #125a28; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--badge-danger-bg); }
.btn-link { background: none; border: 0; padding: 0; height: auto; color: var(--primary); }
.btn-link:hover { background: none; text-decoration: underline; }
td button, td .btn { height: 32px; padding: 0 var(--space-3); }
.nav-toggle:hover { color: var(--text); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; }
.badge-success { background: var(--badge-success-bg); color: var(--badge-success-fg); }
.badge-warning { background: var(--badge-warning-bg); color: var(--badge-warning-fg); }
.badge-danger { background: var(--badge-danger-bg); color: var(--badge-danger-fg); }
.badge-info { background: var(--badge-info-bg); color: var(--badge-info-fg); }
.badge-neutral { background: var(--badge-neutral-bg); color: var(--badge-neutral-fg); }
.badge-gold { background: var(--badge-gold-bg); color: var(--badge-gold-fg); }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--border); margin-bottom: var(--space-4); }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
tr { height: 40px; }
th { background: var(--surface-muted); font-size: var(--fs-label); line-height: 18px; font-weight: 600; position: sticky; top: var(--nav-height); z-index: 5; }
tbody tr:hover, table tr:hover td { background: var(--bg); }
td:first-child a { font-weight: 500; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.dash { color: var(--text-muted); }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-2); }
.pager .btn { height: 32px; padding: 0 var(--space-3); }

/* ---------- Alerts ---------- */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-control); margin-bottom: var(--space-4); font-weight: 500; }
.alert-success { background: var(--badge-success-bg); color: var(--badge-success-fg); }
.alert-warning { background: var(--badge-warning-bg); color: var(--badge-warning-fg); }
.alert-error { background: var(--badge-danger-bg); color: var(--badge-danger-fg); }
.alert-info { background: var(--badge-info-bg); color: var(--badge-info-fg); }

/* ---------- Empty state ---------- */
.empty { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--space-6) var(--space-5); text-align: center; margin-bottom: var(--space-4); }
.empty .icon { font-size: 28px; line-height: 34px; color: var(--text-muted); }
.empty p { margin: var(--space-2) 0 var(--space-4); color: var(--text-muted); }

/* ---------- Login ---------- */
body.login { background: var(--divy-navy); display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: var(--space-4); }
.login-card { background: #fff; border-radius: var(--radius-card); padding: var(--space-6); width: 100%; max-width: 380px; text-align: center; }
.login-card img { height: 120px; max-width: 100%; margin-bottom: var(--space-2); }
.login-card h1 { margin-bottom: var(--space-1); }
.login-card .tagline { color: var(--text-muted); margin: 0 0 var(--space-5); box-shadow: inset 0 -3px 0 var(--divy-orange); display: inline-block; padding-bottom: var(--space-1); }
.login-card form { text-align: left; display: grid; gap: var(--space-3); }
.login-card button { width: 100%; margin-top: var(--space-2); }
.footer { text-align: center; color: var(--text-muted); font-size: var(--fs-meta); padding: var(--space-5); }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Narrow screens: the sidebar slides in from the left ---------- */
@media (max-width: 960px) {
  .nav-toggle { display: block; margin-left: calc(var(--space-2) * -1); }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .shell.nav-open .sidebar { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.3); }
  .shell.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,30,61,.5); z-index: 25; }
  .topbar { padding: 0 var(--space-4); }
  .topbar-title { display: none; }
  .topbar-status { display: none; }
}

/* ---------- Mobile: scrolling tables, card views ---------- */
@media (max-width: 768px) {
  main { padding: var(--space-4); }
  .grid { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  th { position: static; }

  table.cards { display: block; white-space: normal; background: none; border: 0; overflow: visible; }
  table.cards thead, table.cards tr.head { display: none; }
  table.cards tbody { display: block; }
  table.cards tr { display: block; height: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
  table.cards td { display: flex; gap: var(--space-3); justify-content: space-between; align-items: flex-start; border: 0; padding: var(--space-1) 0; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--text-muted); font-size: var(--fs-meta); text-align: left; flex: 0 0 90px; }
  table.cards td:first-child { font-size: 15px; font-weight: 600; text-align: left; display: block; }
  table.cards td:first-child::before { content: none; }
  table.cards td.full { display: block; text-align: left; }
  table.cards td.full::before { display: block; margin-bottom: var(--space-1); }
  table.cards td input, table.cards td select { margin-bottom: var(--space-2); }
  table.cards td button, table.cards td .btn { height: 40px; width: 100%; }
  table.cards a.tel { font-size: 15px; font-weight: 600; }
}


/* click-to-sort table headers */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--divy-orange, #E87038); }
th.sortable[data-dir="asc"]::after { content: " \25B2"; font-size: 10px; }
th.sortable[data-dir="desc"]::after { content: " \25BC"; font-size: 10px; }

/* Route calendar — day-wise grid (click a day to open Day sheet) */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: var(--space-4); }
.cal-dow { text-align: center; font-size: var(--fs-meta); color: var(--text-muted); padding: 4px 0; font-weight: 600; }
.cal-cell { display: block; min-height: 68px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-control);
  padding: 6px 8px; text-decoration: none; color: var(--text); }
.cal-cell.cal-empty { background: transparent; border: none; }
.cal-cell:not(.cal-empty):hover { border-color: var(--divy-orange, #E87038); }
.cal-cell .cal-daynum { font-size: 13px; font-weight: 600; display: block; }
.cal-cell.cal-today .cal-daynum { color: var(--divy-orange, #E87038); }
.cal-cell.has-visits { background: var(--badge-info-bg); }
.cal-cell .cal-count { display: block; font-size: 12px; font-weight: 600; margin-top: 4px; }
.cal-cell .cal-clusters { display: block; font-size: 11px; color: var(--text-muted); line-height: 1.3; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
  .cal-grid { grid-template-columns: repeat(7, 1fr); gap: 3px; }
  .cal-cell { min-height: 52px; padding: 4px; }
  .cal-cell .cal-clusters { display: none; }
}
