/* ═══════════════════════════════════════════════════
   DESIGN SYSTEM — Inspired by Linear / Mercury / Stripe
   Dark-first, razor-sharp, fintech-grade
   ═══════════════════════════════════════════════════ */

:root {
  --bg-0: #ffffff;
  --bg-1: #f8f8fa;
  --bg-2: #f1f1f4;
  --bg-3: #e8e8ed;
  --bg-4: #dddde3;
  --bg-hover: #f0f0f4;
  --bg-active: #eaeaef;
  --surface: rgba(0,0,0,0.02);
  --surface-hover: rgba(0,0,0,0.04);
  --border: rgba(0,0,0,0.07);
  --border-strong: rgba(0,0,0,0.12);
  --border-accent: rgba(99,182,255,0.3);

  --text-0: #111118;
  --text-1: #2d2d3a;
  --text-2: #5a5a6e;
  --text-3: #8a8a9a;
  --text-4: #b0b0bc;

  --accent: #2d8cf0;
  --accent-dim: rgba(45,140,240,0.1);
  --accent-glow: rgba(45,140,240,0.06);
  --green: #22a854;
  --green-dim: rgba(34,168,84,0.1);
  --red: #e5484d;
  --red-dim: rgba(229,72,77,0.1);
  --amber: #d97706;
  --amber-dim: rgba(217,119,6,0.1);
  --purple: #7c5cfc;

  --font: 'Outfit', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 0.2s;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

::selection { background: var(--accent-dim); color: var(--accent); }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

/* ═══════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════ */

#loginScreen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  z-index: 9999;
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

#loginScreen.hiding {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

.login-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, black 20%, transparent 100%);
}

.login-glow {
  position: absolute;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(45,140,240,0.08) 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: pulse 4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 380px;
  max-width: 90vw;
  animation: loginEnter 0.8s var(--ease);
}

@keyframes loginEnter {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-brand {
  text-align: center;
  margin-bottom: 48px;
}

.login-brand img {
  filter: drop-shadow(0 0 20px rgba(45,140,240,0.15));
}

.login-brand h1 {
  font-size: 1.55rem;
  font-weight: 400;
  color: var(--text-0);
  letter-spacing: -0.01em;
}

.login-brand p {
  color: var(--text-3);
  font-size: 0.85rem;
  margin-top: 6px;
  font-weight: 400;
}

.login-field {
  position: relative;
  margin-bottom: 20px;
}

.login-field input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-0);
  font-family: var(--mono);
  font-size: 1.1rem;
  letter-spacing: 0.25em;
  text-align: center;
  outline: none;
  transition: all var(--duration) var(--ease);
}

.login-field input::placeholder {
  color: var(--text-4);
  letter-spacing: 0.15em;
  font-family: var(--font);
  font-size: 0.9rem;
}

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), 0 0 30px rgba(45,140,240,0.06);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.login-btn:hover {
  background: #1a7de0;
  box-shadow: 0 0 30px rgba(45,140,240,0.2);
  transform: translateY(-1px);
}

.login-btn:active { transform: translateY(0); }

.login-error {
  text-align: center;
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 14px;
  height: 20px;
  opacity: 0;
  transition: opacity 0.3s;
}

.login-error.visible { opacity: 1; }

.login-hint {
  text-align: center;
  margin-top: 32px;
  color: var(--text-4);
  font-size: 0.75rem;
}

/* ═══════════════════════════════════════════════════
   APP SHELL — Sidebar + Content
   ═══════════════════════════════════════════════════ */

#app {
  display: none;
  height: 100vh;
}

#app.active {
  display: grid;
  grid-template-columns: 260px 1fr;
  animation: appEnter 0.5s var(--ease);
}

@keyframes appEnter {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-brand {
  padding: 24px 22px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-brand h2 {
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--text-0);
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.sidebar-brand span {
  font-size: 0.7rem;
  color: var(--text-3);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-4);
  padding: 0 10px;
  margin-bottom: 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  font-size: 0.85rem;
  color: var(--text-2);
  font-weight: 450;
  user-select: none;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text-1);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-accent);
  font-weight: 600;
}

.nav-item .icon {
  width: 20px;
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.7;
}

.nav-item.active .icon { opacity: 1; }

.nav-item .badge {
  margin-left: auto;
  font-size: 0.65rem;
  background: var(--bg-4);
  color: var(--text-3);
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
  font-family: var(--mono);
}

.nav-item.active .badge {
  background: rgba(99,182,255,0.2);
  color: var(--accent);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-footer-btn:hover {
  background: var(--red-dim);
  color: var(--red);
  border-color: rgba(248,113,113,0.2);
}

/* ── Content Area ── */
.content {
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-0);
}

.content-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding: 20px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.content-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-0);
  letter-spacing: -0.02em;
}

.content-header p {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.year-pill {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.year-pill button {
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.year-pill button:hover { color: var(--text-0); background: var(--surface-hover); }
.year-pill button.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }

.year-pill .divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.content-body {
  padding: 28px 36px 60px;
}

/* ── Panel transitions ── */
.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: panelIn 0.35s var(--ease);
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════
   COMPONENTS
   ═══════════════════════════════════════════════════ */

/* ── Metric Cards ── */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.metric {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  transition: all 0.2s var(--ease);
}

.metric:hover {
  border-color: var(--border-strong);
  background: var(--bg-3);
}

.metric-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 10px;
}

.metric-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-0);
  letter-spacing: -0.03em;
  font-family: var(--font);
}

.metric-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 500;
}

.metric-sub .up { color: var(--red); }
.metric-sub .down { color: var(--green); }
.metric-sub .neutral { color: var(--text-4); }
.metric-sub .tag {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  font-family: var(--mono);
}
.metric-sub .tag.up { background: var(--red-dim); color: var(--red); }
.metric-sub .tag.down { background: var(--green-dim); color: var(--green); }

/* ── Cards ── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-head {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.card-head h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-0);
  letter-spacing: -0.01em;
}

.card-head p {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 2px;
}

.card-body { padding: 0; }
.card-body.padded { padding: 24px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn-accent:hover {
  background: #1a7de0;
  box-shadow: 0 0 20px rgba(45,140,240,0.15);
  transform: translateY(-1px);
}

.btn-ghost {
  background: var(--bg-3);
  color: var(--text-2);
  border-color: var(--border-strong);
}

.btn-ghost:hover { background: var(--bg-4); color: var(--text-0); }

.btn-danger-ghost {
  background: transparent;
  color: var(--text-3);
  border-color: var(--border);
}

.btn-danger-ghost:hover {
  background: var(--red-dim);
  color: var(--red);
  border-color: rgba(248,113,113,0.2);
}

.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-icon { width: 30px; height: 30px; padding: 0; justify-content: center; font-size: 0.8rem; }

/* ── Tables ── */
.table-container { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 20px;
  text-align: left;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-4);
  font-weight: 600;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

tbody td {
  padding: 11px 20px;
  font-size: 0.84rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }

.td-mono {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 500;
  text-align: right;
  color: var(--text-0);
}

.td-actions {
  text-align: right;
  white-space: nowrap;
}

.td-actions .btn-icon { opacity: 0; transition: opacity 0.15s; }
tbody tr:hover .td-actions .btn-icon { opacity: 1; }

.row-cat td {
  background: rgba(99,182,255,0.04);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  padding: 8px 20px;
}

.row-sub td {
  background: var(--bg-3);
  font-weight: 600;
  font-size: 0.8rem;
}

.row-grand td {
  background: var(--bg-4);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-0);
  border-top: 2px solid var(--border-strong);
}

/* ── Forms ── */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text-0);
  outline: none;
  transition: all var(--duration);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

/* ── Owner Cards ── */
.owners-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  padding: 16px 20px;
}

.owner-tile {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: all 0.2s var(--ease);
  position: relative;
}

.owner-tile:hover {
  border-color: var(--border-strong);
  background: var(--bg-4);
}

.owner-tile-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 10px;
}

.owner-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-0);
}

.owner-units {
  font-size: 0.78rem;
  color: var(--text-3);
  line-height: 1.7;
}

.owner-units code {
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--bg-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent);
}

.owner-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.owner-amount {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.owner-yearly {
  font-size: 0.72rem;
  color: var(--text-4);
}

.owner-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.owner-tile:hover .owner-actions { opacity: 1; }

/* ── Index Preview ── */
.idx-list { list-style: none; }

.idx-item {
  display: grid;
  grid-template-columns: 1fr 140px 140px;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
  align-items: center;
  column-gap: 48px;
}

.idx-item:last-child { border: none; }
.idx-old { color: var(--text-4); text-decoration: line-through; font-family: var(--mono); font-size: 0.8rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.idx-new { color: var(--green); font-family: var(--mono); font-size: 0.8rem; font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.idx-label { color: var(--text-2); }

.idx-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
  padding: 12px 0 4px;
}

.idx-total {
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
  padding-top: 12px;
  margin-top: 4px;
}

/* ── History ── */
.timeline { list-style: none; }

.timeline-item {
  display: flex;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
  box-shadow: 0 0 8px var(--accent-dim);
}

.timeline-text {
  font-size: 0.84rem;
  color: var(--text-1);
  line-height: 1.5;
}

.timeline-time {
  font-size: 0.72rem;
  color: var(--text-4);
  margin-top: 3px;
  font-family: var(--mono);
}

/* ── Bar Chart ── */
.bars { padding: 20px 24px; }

.bar-row {
  display: grid;
  grid-template-columns: 180px 1fr 100px;
  gap: 14px;
  align-items: center;
  margin-bottom: 8px;
}

.bar-label {
  font-size: 0.78rem;
  color: var(--text-2);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 28px;
  background: var(--bg-3);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s var(--ease);
  position: relative;
}

.bar-fill::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08));
}

.bar-value {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-2);
  font-weight: 500;
  text-align: right;
}

/* ── Modal ── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-bg.open {
  display: flex;
  animation: fadeIn 0.15s;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.15);
  animation: modalIn 0.25s var(--ease);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-box h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-0);
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── Toast ── */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-msg {
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  color: var(--text-0);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.3s var(--ease), toastOut 0.3s var(--ease) 2.7s forwards;
}

@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

.toast-msg .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toast-msg.ok .dot { background: var(--green); box-shadow: 0 0 8px var(--green-dim); }
.toast-msg.err .dot { background: var(--red); }
.toast-msg.info .dot { background: var(--accent); }

/* ── Empty ── */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-4);
}

.empty .ico { font-size: 2rem; margin-bottom: 10px; }

/* ── DMJOP Phase Timeline ── */
.phase-timeline {
  position: relative;
  padding-left: 32px;
}

.phase-timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: linear-gradient(to bottom, var(--accent), var(--green), var(--amber), #f97316, var(--red));
  border-radius: 2px;
}

.phase-item {
  position: relative;
  margin-bottom: 20px;
  padding: 20px 24px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.2s var(--ease);
}

.phase-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-3);
}

.phase-dot {
  position: absolute;
  left: -32px;
  top: 24px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-0);
  z-index: 1;
}

.phase-year {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.phase-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-0);
  margin-bottom: 8px;
}

.phase-desc {
  font-size: 0.84rem;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 12px;
}

.phase-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.phase-tag {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--mono);
}

.tag-invest { background: var(--accent-dim); color: var(--accent); }
.tag-subsidy { background: var(--green-dim); color: var(--green); }
.tag-cashflow { background: var(--amber-dim); color: var(--amber); }
.tag-net { background: rgba(167,123,250,0.12); color: var(--purple); }

/* ── KPI Row ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-align: center;
}

.kpi-num {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-0);
  letter-spacing: -0.02em;
}

.kpi-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  margin-top: 4px;
  font-weight: 600;
}

/* ── Solar Visual ── */
.solar-roof {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}

.solar-grid {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 2px;
  max-width: 600px;
  margin: 0 auto;
}

.solar-panel {
  aspect-ratio: 1.6;
  background: linear-gradient(135deg, #1a4a7a, #2d6db5);
  border-radius: 2px;
  border: 1px solid rgba(45,109,181,0.3);
  position: relative;
  overflow: hidden;
}

.solar-panel::after {
  content: '';
  position: absolute;
  inset: 1px;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.08) 50%, transparent 60%);
}

.solar-panel.empty {
  background: var(--bg-4);
  border-color: var(--border);
}

.solar-panel.empty::after { display: none; }

/* ── Finance Waterfall ── */
.waterfall {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 200px;
  padding: 0 10px 30px;
  position: relative;
}

.waterfall::after {
  content: '';
  position: absolute;
  bottom: 28px;
  left: 0; right: 0;
  height: 1px;
  background: var(--border);
}

.wf-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}

.wf-fill {
  width: 100%;
  max-width: 60px;
  border-radius: 6px 6px 0 0;
  transition: height 0.6s var(--ease);
  min-height: 4px;
}

.wf-label {
  font-size: 0.65rem;
  color: var(--text-3);
  text-align: center;
  font-weight: 500;
  position: absolute;
  bottom: -22px;
  white-space: nowrap;
}

.wf-value {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-0);
}

/* ── Subsidy List ── */
.subsidy-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.subsidy-item:last-child { border: none; }

.subsidy-name {
  font-weight: 500;
  font-size: 0.88rem;
  color: var(--text-0);
}

.subsidy-desc {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 2px;
}

.subsidy-amount {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--green);
  font-size: 0.9rem;
  white-space: nowrap;
}

/* ── Advisor Card ── */
.advisor-card {
  background: linear-gradient(135deg, var(--accent-dim), rgba(167,123,250,0.06));
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.advisor-card h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-0);
  margin-bottom: 8px;
}

.advisor-card p {
  font-size: 0.82rem;
  color: var(--text-2);
  line-height: 1.7;
}

/* ── Hamburger ── */
.hamburger {
  display: none;
  width: 36px; height: 36px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 120;
}

.hamburger svg { display: block; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  backdrop-filter: blur(4px);
  z-index: 99;
}

.sidebar-overlay.open { display: block; }

/* ── Responsive ── */
@media (max-width: 860px) {
  #app.active { grid-template-columns: 1fr; }

  .hamburger { display: flex; }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 30px rgba(0,0,0,0.1);
  }

  .content-header { padding: 16px 20px; }
  .content-body { padding: 20px; }
  .bar-row { grid-template-columns: 120px 1fr 80px; }
  .owners-grid { grid-template-columns: 1fr; }
}

/* ── Print ── */
@media print {
  .sidebar, .content-header, .btn, .toasts { display: none !important; }
  .content { height: auto; overflow: visible; }
  .content-body { padding: 0; }
  body { background: white; color: #111; }
  .card { border: 1px solid #ddd; }
  thead th { background: #f5f5f5; color: #333; }
  .metric { border: 1px solid #ddd; background: #fafafa; }
}

/* ═══════ CHAT WIDGET ═══════ */
#chatToggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 180;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 4px 20px rgba(45,140,240,0.25);
  transition: all 0.2s var(--ease);
}
#chatToggle:hover { transform: scale(1.08); box-shadow: 0 6px 30px rgba(45,140,240,0.35); }

#chatPanel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  max-height: 520px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: 0 16px 60px rgba(0,0,0,0.12);
  z-index: 180;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.25s var(--ease);
}

#chatPanel.open { display: flex; }

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-0);
}

#chatClose, #chatRefresh {
  width: 28px; height: 28px;
  border: none;
  background: var(--bg-3);
  border-radius: 6px;
  color: var(--text-3);
  cursor: pointer;
  font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
#chatClose:hover, #chatRefresh:hover { background: var(--bg-4); color: var(--text-0); }
#chatRefresh svg { width: 14px; height: 14px; }
#chatClose svg { width: 14px; height: 14px; }

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 320px;
}

.chat-msg { display: flex; }
.chat-user { justify-content: flex-end; }
.chat-bot { justify-content: flex-start; }

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.6;
}

.chat-user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bot .chat-bubble {
  background: var(--bg-3);
  color: var(--text-1);
  border-bottom-left-radius: 4px;
}

.chat-link-btn {
  display: block;
  margin-top: 8px;
  padding: 6px 12px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(45,140,240,0.2);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.chat-link-btn:hover { background: var(--accent); color: #fff; }

#chatFAQ {
  padding: 8px 16px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chat-faq-btn {
  padding: 5px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-family: var(--font);
  font-size: 0.72rem;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.chat-faq-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: rgba(45,140,240,0.2); }

.chat-input-row {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  padding: 9px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.84rem;
  color: var(--text-0);
  outline: none;
}
.chat-input-row input:focus { border-color: var(--accent); }

#chatSend {
  width: 36px; height: 36px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
#chatSend:hover { background: #1a7de0; }

/* ═══════ HOME TILES ═══════ */
.home-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  font-family: var(--font);
}
.home-tile:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(45,140,240,0.08);
}
.home-tile-icon { font-size: 1.5rem; }
.home-tile-label { font-size: 0.82rem; font-weight: 500; color: var(--text-1); }
.home-tile:hover .home-tile-label { color: var(--accent); }

/* ═══════ SPINNER ═══════ */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════ CHECKBOX FIX ═══════ */
input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* AI status pulse */
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* Mail Outlook style */
.mail-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s; }
.mail-item:hover { background: var(--bg-3); }
.mail-active { background: var(--accent-dim) !important; border-left: 3px solid var(--accent); }
