/* ============================================================
   main.css — Unified design system for rpascale.org
   Replaces: light.css, purple.css
   theme-dark/light.css are openclaw-only — not touched.
   ============================================================ */

/* === 1. VARIABLES & RESET === */
:root {
  --bg:           #f5f5f7;
  --surface:      #ffffff;
  --surface-2:    #f9fafb;
  --border:       #e5e7eb;
  --border-focus: #2563eb;

  --text:         #1f2937;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;

  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-dim:   #dbeafe;

  --success:      #059669;
  --warning:      #d97706;
  --danger:       #dc2626;
  --danger-hover: #b91c1c;

  --radius-sm:    6px;
  --radius:       8px;
  --radius-lg:    12px;

  --shadow-sm:    0 1px 3px rgba(0,0,0,.06);
  --shadow:       0 2px 8px rgba(0,0,0,.07);
  --shadow-lg:    0 4px 16px rgba(0,0,0,.10);

  --font:         system-ui, -apple-system, "Inter", "Segoe UI", sans-serif;
  --font-mono:    "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

textarea, input, select, button { font-family: inherit; font-size: inherit; }

/* === 2. TYPOGRAPHY === */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }

p { margin-bottom: 0.75rem; }
p:last-child { margin-bottom: 0; }

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* === 3. LAYOUT === */
.container        { max-width: 900px;  margin: 0 auto; padding: 0 20px; }
.container-wide   { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.container-narrow { max-width: 640px;  margin: 0 auto; padding: 0 20px; }

.section { padding: 60px 0; }
.section-sm { padding: 32px 0; }

/* Flex helpers */
.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap     { gap: 12px; }
.flex-wrap    { flex-wrap: wrap; }

/* Grid helpers */
.grid          { display: grid; gap: 16px; }
.grid-2        { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3        { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4        { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto     { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }

/* === 4. CARDS & PANELS === */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.card-sub {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

/* Summary grid — 4 cols, collapses on mobile */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

/* Page header — title + actions row */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.page-header h2 {
  margin: 0;
  font-size: 22px;
}

/* === 5. BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-secondary {
  background: var(--border);
  color: #374151;
}
.btn-secondary:hover { background: #d1d5db; color: #374151; }

.btn-danger {
  background: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Legacy global button (for pages not yet migrated) */
button {
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid #152851;
  background-color: #344670;
  color: #f9fafb;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background .15s;
}
button:hover { background-color: var(--accent-hover); }

/* === 6. FORMS === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.form-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.08);
}

textarea {
  resize: vertical;
  min-height: 80px;
  font-size: 14px;
}

/* === 7. TABLES === */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 9px 10px;
  border-bottom: 1px solid #f3f4f6;
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* === 8. NAVIGATION === */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.nav-container {
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.nav-logo:hover { text-decoration: none; color: var(--accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: color .15s, background .15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface-2); }
.nav-links a.active { color: var(--accent); background: var(--accent-dim); }

/* Dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 200;
  overflow: hidden;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  border-radius: 0;
}
.nav-dropdown-menu a:hover { background: var(--surface-2); }

/* Hamburger — hidden on desktop */
.nav-hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all .2s;
}

/* Mobile nav overlay */
.nav-mobile {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 99;
  padding: 12px 20px 20px;
}
.nav-mobile.open { display: block; }
.nav-mobile a {
  display: block;
  padding: 12px 0;
  font-size: 15px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.nav-mobile a:last-child { border-bottom: none; }

/* === 9. COLLAPSIBLES === */
.collapsible-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.collapsible-header .arrow {
  font-size: 12px;
  color: var(--text-light);
  transition: transform .2s;
}
.collapsible-header.open .arrow { transform: rotate(180deg); }

.collapsible-body { display: none; margin-top: 14px; }
.collapsible-body.open { display: block; }

/* === 10. UTILITIES === */

/* P&L colors */
.positive { color: var(--success); }
.negative { color: var(--danger); }
.neutral  { color: var(--text-muted); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-blue   { background: var(--accent-dim); color: var(--accent); }
.badge-green  { background: #d1fae5; color: var(--success); }
.badge-red    { background: #fee2e2; color: var(--danger); }
.badge-gray   { background: var(--border); color: var(--text-muted); }

/* Hint / empty / toast */
.hint {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 8px;
}

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-light);
  font-size: 14px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.toast.show { opacity: 1; }

/* Loading spinner */
#loading {
  text-align: center;
  padding: 30px;
  color: var(--text-light);
}

/* Text utilities */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: 12px; }
.text-bold   { font-weight: 600; }

/* Spacing */
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

/* === 11. PROJECT CARDS (homepage) === */
.projects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.project-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: transform .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
.project-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
  color: inherit;
}
.project-card h3 { margin-top: 0; color: var(--text); font-size: 16px; }
.project-card p  { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.project-card.hidden { display: none !important; }

.project-categories {
  margin-top: auto;
  padding-top: 10px;
  font-size: 11px;
  color: var(--text-light);
}

.project-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 16px;
}

.filter-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active {
  background: var(--text);
  border-color: var(--text);
  color: #f9fafb;
}

/* === 12. FORM COMPONENTS (from light.css) === */

/* Upload dropzone */
.upload-wrapper { display: flex; margin: 6px 0; }

.dropzone {
  width: 160px;
  height: 120px;
  border: 2px dashed #4b5563;
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 8px;
  transition: border-color .15s, color .15s;
}
.dropzone .dz-message { font-size: 0.8rem; line-height: 1.3; }
.dropzone:hover { border-color: #60a5fa; color: var(--text); }

/* Category pills (cashflow page) */
#category-filters { display: flex; flex-direction: column; gap: 12px; }

.category-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.group-header {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 4px;
  width: 100%;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  line-height: 1.4;
  gap: 6px;
}
.category-pill input { display: none; }
.pill-value { font-weight: 500; opacity: 0.8; font-variant-numeric: tabular-nums; }

.pill-green { --bg:#f0fdf4;--border:#22c55e;--bg-checked:#22c55e;--text-checked:white;--bg-hover:#dcfce7; background:var(--bg);border-color:var(--border);color:#166534; }
.pill-green:has(input:checked) { background:var(--bg-checked)!important;color:var(--text-checked)!important; }
.pill-green:hover { background:var(--bg-hover); }

.pill-red { --bg:#fef2f2;--border:#ef4444;--bg-checked:#ef4444;--text-checked:white;--bg-hover:#fee2e2; background:var(--bg);border-color:var(--border);color:#991b1b; }
.pill-red:has(input:checked) { background:var(--bg-checked)!important;color:var(--text-checked)!important; }
.pill-red:hover { background:var(--bg-hover); }

.button-group { display: flex; flex-direction: row; gap: 8px; margin-bottom: 8px; }

/* Output block */
#output {
  text-wrap: wrap;
  background: var(--surface-2);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 100px;
  font-size: 13px;
}

/* === 13. RESPONSIVE === */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .container, .container-wide, .container-narrow { padding: 0 16px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .section { padding: 40px 0; }

  .nav-links, .nav-dropdown-menu { display: none; }
  .nav-hamburger { display: flex; }

  .page-header { flex-direction: column; align-items: flex-start; }

  table { font-size: 12px; }
  th, td { padding: 7px 8px; }
}

@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .btn-lg { width: 100%; justify-content: center; }
}
