/* src/css/app.css */

/* ─── CSS Variables ──────────────────────────────────────────────────────────── */
:root {
  --c-bg:       #0f1117;
  --c-surface:  #1a1d27;
  --c-surface2: #20243a;
  --c-border:   #2d3150;
  --c-text:     #e4e6f0;
  --c-muted:    #7c82a2;
  --c-blue:     #3b82f6;
  --c-green:    #22c55e;
  --c-red:      #ef4444;
  --c-amber:    #f59e0b;
  --c-orange:   #f97316;
  --radius:     8px;
  --shadow:     0 4px 24px rgba(0,0,0,.45);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Login Overlay ──────────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--c-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-box {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 14px;
  padding: 2.25rem 2rem;
  width: 360px;
  box-shadow: var(--shadow);
}
.login-logo {
  font-size: 1.7rem; font-weight: 800; margin-bottom: .25rem; letter-spacing: -.5px;
}
.login-logo span { color: var(--c-blue); }
.login-sub { color: var(--c-muted); font-size: .82rem; margin-bottom: 1.5rem; }
.login-box label { display: block; font-size: .78rem; font-weight: 600; color: var(--c-muted); margin-bottom: .3rem; }
.login-box input {
  width: 100%; background: var(--c-bg); border: 1px solid var(--c-border);
  border-radius: var(--radius); color: var(--c-text); padding: .55rem .75rem;
  font-size: .9rem; margin-bottom: 1rem; outline: none;
  transition: border-color .2s;
}
.login-box input:focus { border-color: var(--c-blue); }
.login-error { color: var(--c-red); font-size: .78rem; min-height: 1.2em; margin-bottom: .75rem; }
.login-btn {
  width: 100%; padding: .65rem; background: var(--c-blue);
  color: #fff; border: none; border-radius: var(--radius);
  font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: background .2s;
}
.login-btn:hover { background: #2563eb; }

/* ─── App Shell ──────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: .7rem 1.5rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.app-header .logo { font-size: 1.1rem; font-weight: 800; letter-spacing: -.3px; flex: 0 0 auto; }
.app-header .logo span { color: var(--c-blue); }
.header-spacer { flex: 1; }
.rate-badge {
  display: flex; align-items: center; gap: .4rem;
  background: var(--c-surface2); border: 1px solid var(--c-border);
  border-radius: 20px; padding: .25rem .75rem; font-size: .8rem;
}
.rate-badge #rateValue { font-weight: 700; color: var(--c-green); }
.period-selectors {
  display: flex; gap: .5rem; align-items: center;
}
.period-selectors select, .period-selectors input[type="number"] {
  background: var(--c-bg); border: 1px solid var(--c-border); color: var(--c-text);
  border-radius: var(--radius); padding: .3rem .6rem; font-size: .82rem; outline: none;
}
.user-info { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--c-muted); }

/* ─── Tabs ────────────────────────────────────────────────────────────────────── */
.tab-nav {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; gap: 0; padding: 0 1.5rem;
}
.tab-btn {
  background: none; border: none; color: var(--c-muted);
  padding: .7rem 1.1rem; font-size: .86rem; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all .2s;
}
.tab-btn:hover { color: var(--c-text); }
.tab-btn.active  { color: var(--c-blue); border-bottom-color: var(--c-blue); }

.tab-section { display: none; padding: 1.5rem; }
.tab-section.active { display: block; }

/* ─── Section Headers ─────────────────────────────────────────────────────────── */
.section-head {
  display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem;
}
.section-head h2 { margin: 0; font-size: 1rem; font-weight: 700; flex: 1; }

/* ─── KPI Grid ────────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .9rem;
  margin-bottom: 1.75rem;
}
.kpi-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  transition: border-color .25s;
}
.kpi-card .kpi-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); margin-bottom: .35rem; }
.kpi-card .kpi-value { font-size: 1.35rem; font-weight: 800; }
.kpi-card .kpi-sub   { font-size: .75rem; color: var(--c-muted); margin-top: .2rem; }
.kpi-card.kpi-green  { border-color: var(--c-green); }
.kpi-card.kpi-green .kpi-value { color: var(--c-green); }
.kpi-card.kpi-red    { border-color: var(--c-red); }
.kpi-card.kpi-red .kpi-value   { color: var(--c-red); }

/* ─── Seed banner ─────────────────────────────────────────────────────────────── */
.seed-banner {
  display: flex; align-items: center; gap: .75rem;
  background: #111827; border: 1px dashed var(--c-amber);
  border-radius: var(--radius); padding: .65rem 1rem; margin-bottom: 1.25rem;
  font-size: .83rem; color: var(--c-amber);
}
.seed-banner.hidden { display: none; }

/* ─── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .9rem; border-radius: var(--radius); border: none;
  font-size: .83rem; font-weight: 600; cursor: pointer;
  transition: all .18s;
}
.btn-primary  { background: var(--c-blue);  color: #fff; }
.btn-primary:hover  { background: #2563eb; }
.btn-success  { background: var(--c-green); color: #000; }
.btn-success:hover  { filter: brightness(1.1); }
.btn-danger   { background: var(--c-red);   color: #fff; }
.btn-danger:hover   { filter: brightness(1.1); }
.btn-ghost    { background: transparent; color: var(--c-muted); border: 1px solid var(--c-border); }
.btn-ghost:hover    { background: var(--c-surface2); color: var(--c-text); }
.btn-icon     { background: transparent; color: var(--c-muted); padding: .25rem .4rem; border-radius: 4px; }
.btn-icon:hover     { background: var(--c-surface2); color: var(--c-text); }
.btn-sm       { font-size: .78rem; padding: .3rem .6rem; }

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--c-border); }
.pnl-table, .data-table {
  width: 100%; border-collapse: collapse; font-size: .82rem;
}
.pnl-table th, .data-table th {
  background: var(--c-surface2); color: var(--c-muted);
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0;
}
.pnl-table td, .data-table td {
  padding: .5rem .75rem; border-bottom: 1px solid var(--c-border);
}
.pnl-table tr:last-child td, .data-table tr:last-child td { border-bottom: none; }
.pnl-table tbody tr:hover, .data-table tbody tr:hover { background: var(--c-surface2); }
.pnl-table tfoot td, .data-table tfoot td {
  background: var(--c-surface2); font-weight: 700;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ─── Forms (Modal‑like wraps) ───────────────────────────────────────────────── */
.form-wrap {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  align-items: center; justify-content: center;
  z-index: 900;
}
.form-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 12px; padding: 1.75rem; width: 420px; max-width: calc(100vw - 2rem);
  box-shadow: var(--shadow);
}
.form-card h3 { margin: 0 0 1.1rem; font-size: .95rem; }
.form-group { margin-bottom: .9rem; }
.form-group label { display: block; font-size: .75rem; font-weight: 700; color: var(--c-muted); margin-bottom: .3rem; }
.form-group input, .form-group select {
  width: 100%; background: var(--c-bg); border: 1px solid var(--c-border);
  color: var(--c-text); border-radius: var(--radius); padding: .5rem .7rem;
  font-size: .87rem; outline: none; transition: border-color .18s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--c-blue); }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.1rem; }
.emp-calc-preview {
  font-size: .78rem; color: var(--c-amber); background: var(--c-surface2);
  border-radius: 6px; padding: .4rem .7rem; margin-top: .25rem; min-height: 1.5em;
}

/* ─── Turnover inputs ─────────────────────────────────────────────────────────── */
.tv-input {
  background: var(--c-bg); border: 1px solid var(--c-border);
  color: var(--c-text); border-radius: 6px; padding: .3rem .6rem;
  width: 140px; text-align: right; font-size: .86rem;
}
.tv-input:focus { outline: none; border-color: var(--c-blue); }

/* ─── Waterfall Chart ─────────────────────────────────────────────────────────── */
.waterfall { margin-top: 1.25rem; }
.wf-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.wf-label { width: 100px; font-size: .8rem; color: var(--c-muted); flex-shrink: 0; text-align: right; }
.wf-bar-wrap { flex: 1; background: var(--c-surface2); border-radius: 4px; height: 26px; overflow: hidden; }
.wf-bar { height: 100%; border-radius: 4px; transition: width .5s ease; }
.wf-bar.pos  { background: var(--c-green); }
.wf-bar.cost { background: var(--c-red); }
.wf-bar.oh   { background: var(--c-orange); }
.wf-bar.neg  { background: var(--c-red); }
.wf-amount { width: 100px; font-size: .82rem; font-variant-numeric: tabular-nums; text-align: right; flex-shrink: 0; }

/* ─── Overhead category summary ──────────────────────────────────────────────── */
.cat-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: .4rem .75rem; border-bottom: 1px solid var(--c-border); font-size: .83rem;
}
.cat-row:last-child { border-bottom: none; font-weight: 700; }
.cat-amt { font-variant-numeric: tabular-nums; text-align: right; }

/* ─── Client perf table (dashboard) ─────────────────────────────────────────── */
#clientPerfTable { font-size: .82rem; }

/* ─── P&L Report ─────────────────────────────────────────────────────────────── */
.pnl-client-block {
  margin-bottom: 1.5rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pnl-client-head {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  padding: .6rem .9rem; background: var(--c-surface2);
  font-size: .83rem; font-weight: 700;
}
.turnover-label { font-weight: 400; font-size: .8rem; color: var(--c-muted); }

/* ─── Bottom Line Grid ───────────────────────────────────────────────────────── */
.bottom-line {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .75rem; margin-top: 1.25rem;
}
.bl-item {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: .75rem 1rem;
}
.bl-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); margin-bottom: .2rem; }
.bl-value { font-size: 1.15rem; font-weight: 800; }

/* ─── Two‑column dashboard layout ───────────────────────────────────────────── */
.dash-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 1rem;
}
.dash-card h3 { margin: 0 0 .75rem; font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); }

/* ─── Badge ──────────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 20px; font-size: .7rem; font-weight: 700; }
.badge-green { background: rgba(34,197,94,.15); color: var(--c-green); }
.badge-slate { background: rgba(124,130,162,.15); color: var(--c-muted); }

/* ─── Utility ──────────────────────────────────────────────────────────────────── */
.text-green  { color: var(--c-green) !important; }
.text-red    { color: var(--c-red)   !important; }
.text-muted  { color: var(--c-muted) !important; }
.text-amber  { color: var(--c-amber) !important; }
.hidden      { display: none !important; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-2 { gap: .5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.flex-1 { flex: 1; }
hr.divider { border: none; border-top: 1px solid var(--c-border); margin: 1.25rem 0; }

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 8px; padding: .7rem 1.1rem;
  font-size: .86rem; font-weight: 600;
  box-shadow: var(--shadow);
  transform: translateY(20px); opacity: 0; pointer-events: none;
  transition: all .25s ease;
}
.toast.show   { transform: translateY(0); opacity: 1; pointer-events: auto; border-color: var(--c-green); color: var(--c-green); }
.toast.show.error { border-color: var(--c-red); color: var(--c-red); }

/* ─── Filter bar ──────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .85rem;
}
.filter-bar select {
  background: var(--c-bg); border: 1px solid var(--c-border); color: var(--c-text);
  border-radius: var(--radius); padding: .35rem .6rem; font-size: .82rem; outline: none;
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-muted); }

/* ─── Print ──────────────────────────────────────────────────────────────────── */
@media print {
  .app-header, .tab-nav, .filter-bar, .btn, .form-wrap, .toast, .seed-banner { display: none !important; }
  .tab-section { display: block !important; }
  body { background: #fff; color: #000; }
  .kpi-card, .dash-card, .pnl-client-block { border: 1px solid #ccc; }
}

/* ─── HTML class aliases (matching actual index.html class names) ────────────── */

/* Generic input style */
.input {
  background: var(--c-bg); border: 1px solid var(--c-border); color: var(--c-text);
  border-radius: var(--radius); padding: .45rem .7rem; font-size: .87rem; outline: none;
  transition: border-color .18s; width: 100%;
}
.input:focus { border-color: var(--c-blue); }
.input-sm { width: auto; min-width: 80px; max-width: 160px; }

/* .card = surface card container */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.card-title {
  font-size: .85rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--c-muted); margin: 0 0 .75rem;
}
.card-header-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .75rem; gap: .5rem; flex-wrap: wrap;
}

/* .dashboard-grid — same as .dash-grid */
.dashboard-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem;
}
.dashboard-grid .span-2 { grid-column: span 2; }
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid .span-2 { grid-column: span 1; }
}

/* .two-col layout for Clients & Agents tab */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem;
}
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* .table-wrap = horizontal scroll wrapper */
.table-wrap { overflow-x: auto; }
.table-wrap table, .card table {
  width: 100%; border-collapse: collapse; font-size: .82rem;
}
.table-wrap th, .card table th {
  background: var(--c-surface2); color: var(--c-muted);
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--c-border);
}
.table-wrap td, .card table td {
  padding: .5rem .75rem; border-bottom: 1px solid var(--c-border);
}
.table-wrap tr:last-child td, .card table tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover, .card table tbody tr:hover { background: var(--c-surface2); }
.table-wrap tfoot td, .card table tfoot td {
  background: var(--c-surface2); font-weight: 700; border-top: 1px solid var(--c-border);
}

/* Inline form strip (shown inside cards, not a modal) */
.inline-form {
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  background: var(--c-surface2); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .75rem;
}
.inline-form .input { width: auto; flex: 1; min-width: 130px; }

/* Calc preview strip inside employee form */
.calc-preview {
  font-size: .78rem; color: var(--c-amber); background: transparent;
  width: 100%; padding: .2rem 0; min-height: 1.2em;
}

/* Filter row */
.filter-row {
  display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; font-size: .82rem;
}
.filter-row label { color: var(--c-muted); }
.filter-row select {
  background: var(--c-bg); border: 1px solid var(--c-border); color: var(--c-text);
  border-radius: var(--radius); padding: .3rem .6rem; font-size: .82rem; outline: none;
}

/* .toolbar strip above report */
.toolbar {
  display: flex; gap: .5rem; align-items: center; margin-bottom: .85rem; flex-wrap: wrap;
}

/* .section-label heading */
.section-label {
  font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--c-muted); margin: 1.25rem 0 .5rem;
}

/* .muted text */
.muted { color: var(--c-muted); font-size: .82rem; margin: 0 0 .5rem; }

/* .totals-table — slightly different style */
.totals-table { margin-top: 1rem; }
.totals-table .section-head { font-weight: 700; color: var(--c-text); }

/* Header layout */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.header-left, .header-right {
  display: flex; align-items: center; gap: .75rem;
}
.app-header h1 {
  font-size: .95rem; font-weight: 700; margin: 0; color: var(--c-muted);
}
.rate-label { font-size: .75rem; color: var(--c-muted); }
.rate-value { font-weight: 700; color: var(--c-green); }
.rate-refresh {
  background: none; border: none; color: var(--c-muted); cursor: pointer;
  font-size: .9rem; padding: 0 .2rem; line-height: 1;
}
.rate-refresh:hover { color: var(--c-blue); }
.period-selector { display: flex; gap: .4rem; }
.period-selector select {
  background: var(--c-bg); border: 1px solid var(--c-border); color: var(--c-text);
  border-radius: var(--radius); padding: .3rem .6rem; font-size: .82rem; outline: none;
}

/* .app-main padding */
.app-main { padding: 1.25rem 1.5rem; }

/* .tab-content (alias for .tab-section) */
.tab-content { display: none; }
.tab-content.active { display: block; }

