/* APD CRM - mobile-first */
:root {
  --blue: #1e3a6e; --blue-dark: #2a4c8c; --bg: #f4f6fa; --card: #fff;
  --text: #111827; --muted: #6b7280; --border: #e5e7eb; --green: #16a34a;
  --warn-bg: #fef3c7; --warn-border: #f59e0b; --error: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; --muted: #94a3b8; --border: #334155; }
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  padding-bottom: 4.5rem; /* clears the fixed values footer */
}

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--blue); color: #fff; padding: .85rem 1.25rem;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 1.5rem; letter-spacing: .02em; display: flex; align-items: center; gap: .65rem; }
.brand-logo { height: 66px; width: 66px; border-radius: 50%; background: #fff; padding: 3px; object-fit: contain; }

/* Core values footer — fixed to the bottom of the viewport */
.values-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; gap: 1rem; flex-wrap: wrap;
  background: var(--blue); color: #fff;
  padding: 1.1rem 1rem;
  font-size: 1.5rem; font-weight: 800; letter-spacing: .02em;
  box-shadow: 0 -2px 12px rgba(0,0,0,.15);
}
.values-footer i { color: #7f9bd0; font-size: 1rem; }
@media (max-width: 560px) {
  body { padding-bottom: 3.6rem; }
  .values-footer { font-size: 1.05rem; gap: .55rem; padding: .8rem .6rem; }
  .values-footer i { font-size: .7rem; }
}
#tabs { display: flex; gap: .25rem; flex: 1; }
.tab {
  background: transparent; color: #cbd5e1; border: none; padding: .45rem .8rem;
  border-radius: 8px; font-size: .95rem; cursor: pointer;
}
.tab.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.whoami { font-size: .85rem; opacity: .9; }
.logout { color: #cbd5e1; font-size: .82rem; text-decoration: none; }
.logout:hover { color: #fff; text-decoration: underline; }

main { max-width: 860px; margin: 0 auto; padding: 1rem; }
h2 { font-size: 1.2rem; margin: .8rem 0 .4rem; }
h3 { font-size: .95rem; margin: 1.1rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }

.weekbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; text-align: center; }
.weekbar h2 { margin: 0; }

.banner { padding: .7rem .9rem; border-radius: 10px; margin: .6rem 0; }
.banner.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #78350f; }

.progress-wrap { display: flex; align-items: center; gap: .7rem; margin: .5rem 0 .8rem; }
.progress { flex: 1; height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--green); transition: width .3s; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .6rem 0 .2rem; }
.spacer { flex: 1; }
button { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent; padding: .55rem .95rem; }
button.primary { background: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--blue-dark); }
button.secondary { background: var(--card); border-color: var(--blue); color: var(--blue); font-weight: 600; }
button.ghost { background: transparent; border-color: var(--border); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }

.dash-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.dash-top h2 { margin: 0; }
.dash-h { display: flex; align-items: center; gap: .5rem; }
.dash-h .count { background: var(--border); color: var(--text); border-radius: 999px; padding: 0 .55rem; font-size: .75rem; }
.dash-h.overdue { color: var(--error); }
.dash-h.today { color: #92400e; }
.dash-h.tomorrow { color: var(--blue); }
#team-stats { margin: -.3rem 0 .8rem; }
.mysales-head { font-weight: 700; color: var(--blue); margin-bottom: .4rem; }
.mysales-row { display: grid; grid-template-columns: 6rem 6.5rem minmax(4rem, 1fr) auto; align-items: center; gap: .7rem; padding: .3rem 0; }
.mysales-label { color: var(--muted); font-size: .9rem; }
.mysales-val { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.mysales-pct { white-space: nowrap; }
.sales-group { margin-bottom: .8rem; }
.sales-group-head { font-weight: 700; color: var(--blue); margin-bottom: .5rem; }
.sales-table th, .sales-table td { padding: .5rem .6rem; }
.sales-table .sr-name { font-weight: 600; }
.sales-table .sr-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sales-table .sr-bar { min-width: 8rem; }
.goalbar { display: inline-block; width: calc(100% - 3rem); height: .55rem; background: var(--border); border-radius: 999px; overflow: hidden; vertical-align: middle; }
.goalbar-fill { height: 100%; border-radius: 999px; }
.goalbar-fill.done { background: var(--green); }
.goalbar-fill.ok { background: var(--blue); }
.goalbar-fill.low { background: var(--warn-border); }
.sales-table .sr-pct { display: inline-block; width: 2.6rem; text-align: right; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sales-table tr.sales-total td { border-top: 2px solid var(--border); font-weight: 700; }
.team-chart { display: flex; flex-direction: column; gap: .55rem; }
#team-managers { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .8rem; }
.mgr-card { margin-bottom: 0; }
.mgr-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .45rem; }
.mgr-progress { height: .55rem; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: .6rem; }
.mgr-progress div { height: 100%; background: var(--green); border-radius: 999px; }
.mgr-types { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .6rem; }
.type-pill { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .6rem; font-size: .75rem; }
.type-pill b.ok { color: var(--green); }
.type-pill b.warn { color: var(--error); }
.mgr-reps { list-style: none; padding: 0; margin: 0; }
.mgr-reps > li { display: flex; justify-content: space-between; gap: .6rem; padding: .3rem 0; border-top: 1px solid var(--border); font-size: .88rem; }
.mgr-reps > li.clickable { cursor: pointer; }
.mgr-reps > li.clickable:hover { color: var(--blue); }
.mgr-reps .chev { font-style: normal; display: inline-block; margin-right: .35rem; color: var(--muted); transition: transform .15s; }
.mgr-reps > li.open .chev { transform: rotate(90deg); }
.mgr-reps > li.member-detail { display: block; background: var(--bg); border-radius: 8px; padding: .5rem .65rem; border-top: none; }
.bar-row { display: grid; grid-template-columns: minmax(6rem, 10rem) 1fr 3.4rem; align-items: center; gap: .7rem; }
.bar-label { font-size: .85rem; font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-total { background: var(--border); border-radius: 6px; height: 1.15rem; overflow: hidden; min-width: 3px; }
.bar-done { background: var(--green); height: 100%; }
.bar-count { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.bar-legend { display: flex; gap: 1.1rem; margin-top: .45rem; font-size: .75rem; color: var(--muted); }
.bar-legend .sw { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .35rem; vertical-align: -2px; }
.sw.done { background: var(--green); }
.sw.open { background: var(--border); }
.daygroups { display: flex; flex-direction: column; }
.day-head {
  font-size: .78rem; font-weight: 700; color: var(--blue); text-transform: uppercase;
  letter-spacing: .05em; margin: .9rem 0 .4rem; padding-bottom: .25rem;
  border-bottom: 1px solid var(--border);
}
.daygroups .day-head:first-child { margin-top: .2rem; }
.tasklist { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.tasklist li {
  display: flex; gap: .7rem; align-items: flex-start;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: .65rem .8rem;
}
.tasklist li.done .task-subject { text-decoration: line-through; color: var(--muted); }
.tasklist li.overdue { border-left: 3px solid var(--error); }
.tasklist li.today { border-left: 3px solid var(--warn-border); }
.due-badge {
  display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; padding: .08rem .42rem; border-radius: 999px; vertical-align: middle; margin-left: .4rem;
}
.due-badge.overdue { background: var(--error); color: #fff; }
.due-badge.today { background: var(--warn-bg); color: #92400e; border: 1px solid var(--warn-border); }
.check input { width: 1.35rem; height: 1.35rem; accent-color: var(--green); margin-top: .1rem; }
.task-subject { font-weight: 600; }
.task-body { flex: 1; min-width: 0; }
.task-edit {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: .25rem .4rem; border-radius: 6px; align-self: center;
}
.task-edit:hover { color: var(--blue); background: rgba(30,64,110,.08); }
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--card); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { background: rgba(30,64,175,.07); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1.2rem; }
.card label { display: block; margin-bottom: .7rem; font-size: .9rem; font-weight: 600; }
.card input:not([type=checkbox]), .card select, dialog input:not([type=checkbox]), dialog select, dialog textarea {
  width: 100%; padding: .5rem .6rem; margin-top: .25rem; font: inherit;
  border: 1.5px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
.edit-table input:not([type=checkbox]), .edit-table select { width: 100%; min-width: 6rem; margin: 0; }
.card label.check-inline { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; flex-wrap: wrap; }
.card label.check-inline input { width: auto; margin: 0; }
.card select.inline-select { width: auto; margin: 0; padding: .25rem .4rem; }
#test-banner {
  background: var(--error); color: #fff; text-align: center; font-weight: 700;
  font-size: .85rem; letter-spacing: .06em; padding: .4rem .8rem; text-transform: uppercase;
}
.linkish { background: none; border: none; padding: 0; color: var(--blue); text-decoration: underline; cursor: pointer; font: inherit; font-size: .85rem; }
.row-del { background: transparent; border: none; color: var(--error); font-size: 1rem; line-height: 1; padding: .2rem .4rem; cursor: pointer; }
.row-del:hover { color: #fff; background: var(--error); border-radius: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.row { display: flex; gap: .6rem; justify-content: flex-end; margin-top: .4rem; }
.row button:first-child { margin-right: auto; }
pre#test-result { white-space: pre-wrap; background: var(--bg); padding: .7rem; border-radius: 8px; font-size: .8rem; }

dialog {
  border: none; border-radius: 14px; padding: 1.2rem; width: min(92vw, 420px);
  background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 .8rem; text-transform: none; color: var(--text); font-size: 1.1rem; }
dialog label { display: block; margin-bottom: .7rem; font-size: .9rem; font-weight: 600; position: relative; }

.autocomplete {
  list-style: none; padding: 0; margin: .2rem 0 0; border: 1px solid var(--border);
  border-radius: 8px; max-height: 180px; overflow-y: auto; background: var(--card);
  position: absolute; width: 100%; z-index: 5;
}
.autocomplete li { padding: .5rem .6rem; cursor: pointer; font-weight: 400; }
.autocomplete li:hover { background: rgba(30,64,175,.09); }

.rep-row { cursor: pointer; }
.rep-row:hover td { background: rgba(30,64,175,.05); }
.detail-row td { background: var(--bg); }
.detail-list { list-style: none; padding: .2rem 0; display: flex; flex-direction: column; gap: .45rem; }
.detail-list li { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.detail-subject { font-weight: 600; }
.done-mark { color: var(--green); font-weight: 700; }
.open-mark { color: var(--muted); }

#toast {
  position: fixed; bottom: 5.5rem; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: .65rem 1.1rem; border-radius: 10px;
  font-size: .92rem; z-index: 100; max-width: 90vw;
}
#toast.error { background: var(--error); }

@media (max-width: 560px) {
  .whoami { display: none; }
  .actions button { flex: 1 1 45%; }
  th, td { font-size: .85rem; padding: .45rem .5rem; }
}
