/* ─── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface2: #f0ede6;
  --border: #e2ddd5;
  --text: #1a1714;
  --text2: #6b6560;
  --text3: #9e9890;
  --accent: #c8601a;
  --accent-light: #fdf0e8;
  --accent-dark: #a04d14;
  --green: #1a7a4a;
  --green-bg: #e8f5ee;
  --blue: #1a5fa8;
  --blue-bg: #e8f0fc;
  --purple: #6b3fa8;
  --purple-bg: #f0eafc;
  --orange: #c8601a;
  --orange-bg: #fdf0e8;
  --red: #c0392b;
  --red-bg: #fdf0ee;
  --yellow: #c8961a;
  --yellow-bg: #fdf6e8;
  --sidebar-w: 240px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.06);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button { cursor: pointer; font-family: inherit; border: none; outline: none; }
input, select, textarea { font-family: inherit; font-size: 14px; outline: none; }
a { text-decoration: none; color: inherit; }

/* ─── Screens ────────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }
.screen.hidden { display: none !important; }
.page { display: none; width: 100%; }
.page.active { display: block; }
.page.hidden { display: none !important; }

/* ─── Auth ───────────────────────────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: #1a1714;
  position: relative;
  overflow: hidden;
}
.auth-bg { position: absolute; inset: 0; pointer-events: none; }
.auth-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.12;
}
.b1 { width: 500px; height: 500px; background: #c8601a; top: -100px; right: -100px; }
.b2 { width: 400px; height: 400px; background: #1a7a4a; bottom: -100px; left: -80px; }
.b3 { width: 300px; height: 300px; background: #6b3fa8; top: 40%; left: 40%; }

.auth-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  padding: 24px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
  justify-content: center;
}
.brand-icon {
  width: 48px; height: 48px;
  background: var(--accent);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: white;
  font-family: 'Playfair Display', serif;
}
.brand-icon.sm { width: 32px; height: 32px; font-size: 16px; border-radius: 8px; }
.brand-text { display: flex; align-items: baseline; gap: 4px; }
.brand-name { font-family: 'Playfair Display', serif; font-size: 26px; font-weight: 700; color: white; }
.brand-ai { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--accent); background: rgba(200,96,26,0.15); padding: 2px 6px; border-radius: 4px; }

.auth-card {
  background: white;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
}
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  transition: all 0.2s;
  margin-bottom: -1px;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { display: none; }
.auth-form.active { display: block; }
.auth-note { text-align: center; font-size: 12px; color: var(--text3); margin-top: 16px; }

/* ─── App Shell ──────────────────────────────────────────────────────────── */
#app-shell {
  height: 100vh;
  display: flex;
  overflow: hidden;
}
.sidebar {
  width: var(--sidebar-w);
  background: var(--text);
  display: flex;
  flex-direction: column;
  padding: 0;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-family: 'Playfair Display', serif;
  font-size: 17px;
  font-weight: 600;
  color: white;
}
.ai-badge {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--accent);
  background: rgba(200,96,26,0.2);
  padding: 1px 5px;
  border-radius: 3px;
}
.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.55);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.nav-item svg { width: 16px; height: 16px; }
.nav-item:hover { color: white; background: rgba(255,255,255,0.08); }
.nav-item.active { color: white; background: rgba(200,96,26,0.25); }
.sidebar-bottom { padding: 16px 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-pill { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-info span:first-child { font-size: 13px; font-weight: 500; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-badge { font-size: 10px; padding: 1px 6px; border-radius: 10px; font-family: 'DM Mono', monospace; width: fit-content; }
.plan-badge.free { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.5); }
.plan-badge.pro { background: rgba(200,96,26,0.3); color: #f5a76a; }

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
  background: var(--bg);
}

/* ─── Page Headers ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-title { font-family: 'Playfair Display', serif; font-size: 28px; font-weight: 700; line-height: 1.2; }
.page-sub { color: var(--text2); font-size: 14px; margin-top: 4px; }

/* ─── Stats ──────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid;
}
.stat-card.green { border-color: var(--green); }
.stat-card.orange { border-color: var(--orange); }
.stat-card.blue { border-color: var(--blue); }
.stat-card.purple { border-color: var(--purple); }
.stat-label { font-size: 12px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-family: 'Playfair Display', serif; font-size: 26px; font-weight: 700; margin: 8px 0 4px; }
.stat-sub { font-size: 12px; color: var(--text3); }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card.no-pad { padding: 0; overflow: hidden; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 600; }
.link { color: var(--accent); font-size: 13px; font-weight: 500; cursor: pointer; }
.link:hover { text-decoration: underline; }

.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.empty-cell { text-align: center; color: var(--text3); padding: 32px; font-style: italic; }

/* ─── Status Badges ──────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: 'DM Mono', monospace;
}
.status-draft { background: var(--surface2); color: var(--text2); }
.status-sent { background: var(--blue-bg); color: var(--blue); }
.status-paid { background: var(--green-bg); color: var(--green); }
.status-overdue { background: var(--red-bg); color: var(--red); }

/* ─── Filter Bar ─────────────────────────────────────────────────────────── */
.filter-bar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.search-input {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  width: 240px;
  font-size: 14px;
}
.filter-tabs { display: flex; gap: 4px; }
.filter-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  background: white;
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.filter-tab.active, .filter-tab:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ─── Clients Grid ───────────────────────────────────────────────────────── */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.client-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
}
.client-avatar {
  width: 40px; height: 40px;
  background: var(--accent-light);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: var(--accent);
  margin-bottom: 12px;
  font-family: 'Playfair Display', serif;
}
.client-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.client-company { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.client-email { font-size: 12px; color: var(--text3); }
.client-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ─── Invoice List (dashboard) ───────────────────────────────────────────── */
.invoice-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.invoice-list-item:last-child { border-bottom: none; }
.inv-number { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--text2); }
.inv-client { font-weight: 500; font-size: 14px; }
.inv-amount { font-weight: 600; font-family: 'Playfair Display', serif; font-size: 15px; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary svg { width: 16px; height: 16px; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary.full { width: 100%; justify-content: center; }
.btn-secondary { padding: 10px 20px; background: white; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; transition: all 0.15s; }
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { padding: 8px 16px; background: transparent; color: var(--text2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; transition: all 0.15s; }
.btn-ghost:hover { background: var(--bg); }
.btn-ghost.sm { padding: 6px 12px; font-size: 12px; color: rgba(255,255,255,0.4); border-color: rgba(255,255,255,0.15); }
.btn-ghost.sm:hover { color: white; border-color: rgba(255,255,255,0.4); }
.btn-ghost-sm { padding: 6px 12px; background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; color: var(--text2); }
.btn-sm { padding: 6px 14px; background: var(--accent); color: white; border-radius: 6px; font-size: 12px; font-weight: 500; }
.btn-danger { padding: 7px 14px; background: none; color: var(--red); border: 1px solid var(--red); border-radius: 6px; font-size: 13px; }
.btn-danger:hover { background: var(--red-bg); }
.btn-ai { padding: 6px 14px; background: linear-gradient(135deg, #6b3fa8, #c8601a); color: white; border-radius: 6px; font-size: 12px; font-weight: 500; }
.btn-success { padding: 8px 16px; background: var(--green); color: white; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,96,26,0.08);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-error { color: var(--red); font-size: 13px; padding: 8px 12px; background: var(--red-bg); border-radius: 6px; margin-bottom: 12px; }
.hidden { display: none !important; }

/* ─── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}
.modal.large { max-width: 920px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-family: 'Playfair Display', serif; font-size: 22px; font-weight: 600; }
.modal-close { width: 32px; height: 32px; background: var(--bg); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--text2); }
.modal-close:hover { background: var(--border); }
.modal-body { padding: 24px 28px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 28px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; }

/* ─── Invoice Form ───────────────────────────────────────────────────────── */
.invoice-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.form-section { margin-bottom: 24px; }
.form-section h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text2); margin-bottom: 14px; }
.section-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-header-row h4 { margin-bottom: 0; }

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 80px 100px auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.line-item-row input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.line-item-row input:focus { border-color: var(--accent); }
.item-amount { font-family: 'DM Mono', monospace; font-size: 13px; color: var(--text2); padding: 8px 4px; min-width: 90px; text-align: right; }
.remove-item { width: 28px; height: 28px; background: var(--red-bg); color: var(--red); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 16px; line-height: 1; flex-shrink: 0; }
.remove-item:hover { background: var(--red); color: white; }

.totals-section { border-top: 1px solid var(--border); padding-top: 16px; }
.total-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.total-row.grand { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 12px; font-weight: 700; font-size: 18px; font-family: 'Playfair Display', serif; }
.inline-input { width: 80px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; text-align: right; font-size: 13px; }

.client-select-row { margin-bottom: 8px; }
.ai-row { display: flex; gap: 8px; align-items: center; }
.ai-input-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; padding: 10px; background: var(--accent-light); border-radius: 8px; }
.ai-input-row input { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* ─── Invoice Preview ────────────────────────────────────────────────────── */
.invoice-preview {
  background: white;
  padding: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.inv-preview-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 32px; }
.inv-preview-brand { font-family: 'Playfair Display', serif; font-size: 22px; font-weight: 700; color: var(--accent); }
.inv-preview-number { font-family: 'DM Mono', monospace; font-size: 18px; color: var(--text2); }
.inv-preview-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.inv-party-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text3); margin-bottom: 6px; }
.inv-party-name { font-weight: 600; font-size: 15px; }
.inv-preview-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.inv-preview-table th { padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; background: var(--bg); color: var(--text2); }
.inv-preview-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.inv-preview-totals { display: flex; justify-content: flex-end; }
.inv-totals-box { width: 240px; }
.inv-total-line { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.inv-total-line.grand { border-top: 2px solid var(--text); margin-top: 8px; padding-top: 10px; font-weight: 700; font-size: 16px; }

/* ─── Billing ────────────────────────────────────────────────────────────── */
.billing-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; max-width: 700px; }
.plan-card { background: white; border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); border: 2px solid var(--border); }
.plan-card.pro-card { border-color: var(--accent); }
.plan-badge-lg { font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); margin-bottom: 8px; }
.plan-badge-lg.pro { color: var(--accent); }
.plan-price { font-family: 'Playfair Display', serif; font-size: 36px; font-weight: 700; margin-bottom: 20px; }
.plan-price span { font-size: 15px; font-weight: 400; color: var(--text2); }
.plan-features { list-style: none; margin-bottom: 28px; }
.plan-features li { padding: 6px 0; font-size: 14px; color: var(--text2); border-bottom: 1px solid var(--border); }
.plan-features li:last-child { border-bottom: none; }
.current-plan { text-align: center; padding: 10px; background: var(--green-bg); color: var(--green); border-radius: 8px; font-weight: 500; font-size: 13px; }

/* ─── Plan Usage Widget ──────────────────────────────────────────────────── */
.usage-bar-bg { background: var(--border); border-radius: 20px; height: 8px; margin: 8px 0 4px; }
.usage-bar { height: 8px; border-radius: 20px; background: var(--accent); transition: width 0.5s; }
.usage-label { font-size: 12px; color: var(--text2); }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.3s ease;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Empty States ───────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text3); font-style: italic; }
.empty-state.sm { padding: 24px; font-size: 13px; }

/* ─── Action buttons in table ────────────────────────────────────────────── */
.table-actions { display: flex; gap: 6px; }
.table-actions button { padding: 4px 10px; font-size: 12px; border-radius: 5px; font-weight: 500; }
