/* ═══════════════════════════════════════════════════════
   Agency Budget Manager — Stylesheet
   ═══════════════════════════════════════════════════════ */

/* ── Design tokens ───────────────────────────────────── */
:root {
  --c-text:        #1a1a18;
  --c-muted:       #6b6963;
  --c-success:     #1a7a4a;
  --c-danger:      #b93828;
  --c-info:        #1a5f9e;
  --c-bg:          #f5f4f0;
  --c-surface:     #ffffff;
  --c-surface2:    #f0efe9;
  --c-bg-success:  #e8f5ef;
  --c-bg-danger:   #fdf0ee;
  --c-border:      rgba(0,0,0,0.10);
  --c-border2:     rgba(0,0,0,0.16);
  --c-border3:     rgba(0,0,0,0.26);
  --font:          'Suwannaphum', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --r-md:          8px;
  --r-lg:          12px;
  --sidebar:       200px;
  --transition:    0.12s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-text:        #e6e4de;
    --c-muted:       #9a9890;
    --c-success:     #4aad74;
    --c-danger:      #e06e5e;
    --c-info:        #6aaee0;
    --c-bg:          #181816;
    --c-surface:     #202020;
    --c-surface2:    #282826;
    --c-bg-success:  #0c2418;
    --c-bg-danger:   #281210;
    --c-border:      rgba(255,255,255,0.08);
    --c-border2:     rgba(255,255,255,0.13);
    --c-border3:     rgba(255,255,255,0.22);
  }
}

/* ── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar);
  background: var(--c-surface);
  border-right: 0.5px solid var(--c-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.s-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 14px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text);
  border-bottom: 0.5px solid var(--c-border);
  letter-spacing: -0.2px;
}
.s-logo i { font-size: 20px; opacity: 0.65; }

.s-group {
  padding: 14px 14px 3px;
  font-size: 9px;
  font-weight: 700;
  color: var(--c-muted);
  letter-spacing: 1px;
}

.ni {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--c-muted);
  font-size: 13px;
  font-family: var(--font);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  border-right: 2px solid transparent;
  transition: all var(--transition);
}
.ni i { font-size: 15px; }
.ni:hover { background: var(--c-surface2); color: var(--c-text); }
.ni.on   { background: var(--c-surface2); color: var(--c-text); font-weight: 700; border-right-color: var(--c-text); }

.s-foot {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 0.5px solid var(--c-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.save-pill { font-size: 11px; color: var(--c-muted); padding: 2px 0; }

.foot-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  border: 0.5px solid var(--c-border);
  border-radius: var(--r-md);
  cursor: pointer;
  background: none;
  color: var(--c-muted);
  font-family: var(--font);
  font-size: 11px;
  text-align: left;
  transition: all var(--transition);
}
.foot-btn:hover        { background: var(--c-surface2); color: var(--c-text); }
.foot-btn.danger:hover { background: var(--c-bg-danger); color: var(--c-danger); border-color: var(--c-danger); }
.foot-btn.pdf-btn      { color: #a78bfa; border-color: #a78bfa44; }
.foot-btn.pdf-btn:hover{ background: #a78bfa18; color: #c4b5fd; border-color: #a78bfa; }
.foot-btn.pdf-btn.loading { opacity: 0.6; cursor: wait; }

/* ── Main content ────────────────────────────────────── */
.main {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  background: var(--c-bg);
  min-width: 0;
}

/* ── Loading ─────────────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 240px;
  color: var(--c-muted);
  gap: 14px;
}
.loading i { font-size: 44px; opacity: 0.25; }

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--c-border2);
  border-top-color: var(--c-muted);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page header ─────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: 9px;
}
.page-title i { font-size: 22px; opacity: 0.6; }

.item-count {
  font-size: 13px;
  font-weight: 400;
  color: var(--c-muted);
}

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 18px 22px;
  margin-bottom: 16px;
}

.sec-inset {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 16px 20px;
  margin-bottom: 14px;
}

.sec-head {
  font-size: 10px;
  font-weight: 700;
  color: var(--c-muted);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

/* ── Dashboard metrics ───────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.dc {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}
.dl  { font-size: 11px; color: var(--c-muted); margin-bottom: 4px; }
.dv  { font-size: 21px; font-weight: 700; line-height: 1.2; }
.ds  { font-size: 11px; color: var(--c-muted); margin-top: 3px; }

/* ── Bar chart ───────────────────────────────────────── */
.alloc      { margin-bottom: 9px; }
.alloc-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--c-muted); margin-bottom: 3px; }
.bt { height: 5px; background: var(--c-border); border-radius: 3px; overflow: hidden; }
.bf { height: 5px; border-radius: 3px; transition: width 0.35s ease; }

/* ── Revenue rows ────────────────────────────────────── */
.rev-row   { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 0.5px solid var(--c-border); font-size: 13px; }
.rev-row:last-child { border-bottom: none; }
.rev-name  { color: var(--c-muted); }
.rev-amt   { font-weight: 700; color: var(--c-success); }
.rev-total { display: flex; justify-content: space-between; padding: 10px 0 0; font-size: 14px; font-weight: 700; border-top: 1px solid var(--c-border2); margin-top: 4px; }

/* ── Budget table ────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  font-size: 10px;
  font-weight: 700;
  color: var(--c-muted);
  padding: 6px 6px 8px;
  border-bottom: 1px solid var(--c-border2);
  text-align: left;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.tbl td {
  padding: 3px 4px;
  border-bottom: 0.5px solid var(--c-border);
  vertical-align: middle;
}
.tbl tr:hover > td { background: var(--c-surface2); }

.ci {
  background: transparent;
  border: none;
  color: var(--c-text);
  font-size: 13px;
  font-family: var(--font);
  width: 100%;
  padding: 4px 3px;
  outline: none;
}
.ci:focus {
  outline: 1px solid var(--c-border3);
  border-radius: 4px;
  background: var(--c-surface);
}
.cn { text-align: right; }

.csel {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border2);
  color: var(--c-muted);
  font-size: 11px;
  font-family: var(--font);
  border-radius: 5px;
  padding: 3px 4px;
  width: 100%;
}

.del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--c-muted);
  padding: 4px 6px;
  font-size: 15px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  transition: all var(--transition);
}
.del:hover { color: var(--c-danger); background: var(--c-bg-danger); }

.add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 0.5px dashed var(--c-border2);
  border-radius: var(--r-md);
  cursor: pointer;
  background: none;
  color: var(--c-muted);
  font-size: 13px;
  font-family: var(--font);
  margin-top: 10px;
  transition: all var(--transition);
}
.add-btn:hover { background: var(--c-surface); color: var(--c-text); border-style: solid; }

.tot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--c-surface2);
  border-radius: var(--r-md);
  margin-top: 12px;
  font-size: 13px;
}
.tv { font-weight: 700; }

/* ── Revenue calculator ──────────────────────────────── */
.rcalc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 860px) { .rcalc { grid-template-columns: 1fr; } }

.slr { margin-bottom: 13px; }
.slm { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.slk { color: var(--c-muted); }
.slv { font-weight: 700; }

input[type=range] {
  width: 100%;
  accent-color: var(--c-text);
  cursor: pointer;
}

.rs  { padding: 7px 0; border-bottom: 0.5px solid var(--c-border); }
.rs:last-of-type { border-bottom: none; }
.rst { display: flex; justify-content: space-between; margin-bottom: 2px; }
.rn  { color: var(--c-muted); font-size: 13px; }
.ra  { font-weight: 700; color: var(--c-success); font-size: 13px; }
.rno { font-size: 11px; color: var(--c-muted); }
.rev-sum { display: flex; justify-content: space-between; padding: 10px 0 0; font-size: 14px; font-weight: 700; border-top: 1px solid var(--c-border2); margin-top: 4px; }

/* ── Timeline ────────────────────────────────────────── */
.phase-card {
  border-left: 3px solid #378ADD;
  padding: 14px 18px;
  border-radius: 0 var(--r-lg) var(--r-lg) 0;
  margin-bottom: 12px;
  background: var(--c-surface);
  border-top: 0.5px solid var(--c-border);
  border-right: 0.5px solid var(--c-border);
  border-bottom: 0.5px solid var(--c-border);
}
.phase-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.phase-budgets { display: flex; gap: 10px; margin-bottom: 10px; align-items: flex-end; }
.pb { flex: 1; }
.pb label { display: block; font-size: 10px; color: var(--c-muted); font-weight: 700; letter-spacing: 0.5px; margin-bottom: 3px; }
.pb-total { font-size: 13px; font-weight: 700; padding-bottom: 4px; white-space: nowrap; }
textarea.ci { resize: vertical; line-height: 1.6; font-size: 12px; }

/* ── Note box ────────────────────────────────────────── */
.nbox {
  font-size: 12px;
  color: var(--c-muted);
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  margin-top: 14px;
  line-height: 1.7;
  display: flex;
  gap: 8px;
}
.nbox i { opacity: 0.6; flex-shrink: 0; margin-top: 1px; }

/* ── Retry button (error state) ──────────────────────── */
.retry-btn {
  margin-top: 14px;
  padding: 8px 18px;
  border: 0.5px solid var(--c-border2);
  border-radius: var(--r-md);
  background: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  color: var(--c-text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.retry-btn:hover { background: var(--c-surface2); }
