@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@600;700;800&display=swap');

:root {
  --bg: #f8f9fb;
  --bg-white: #ffffff;
  --surface: #ffffff;
  --border: #e8eaed;
  --border-hover: #d1d5db;
  --accent: #4f46e5;
  --accent-light: #eef2ff;
  --accent-text: #4338ca;
  --text: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --yellow: #d97706;
  --yellow-bg: #fffbeb;
  --gray-bg: #f3f4f6;
  --gray-border: #e5e7eb;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --topbar-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── TOPBAR ── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 100;
}

.brand {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
}

.brand-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
  -webkit-text-fill-color: #fff;
}

.topbar nav { display: flex; align-items: center; gap: 2px; }

.topbar nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.topbar nav a:hover { color: var(--text); background: var(--gray-bg); }
.topbar nav a.active {
  color: var(--accent-text);
  background: var(--accent-light);
  font-weight: 600;
}

/* ── LAYOUT ── */
.container {
  max-width: 1060px;
  margin: 0 auto;
  padding: calc(var(--topbar-h) + 32px) 24px 56px;
  animation: fadeUp 0.3s ease both;
}

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

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ── STAT CARDS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  transition: box-shadow 0.15s;
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-label {
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.stat-value.red   { color: var(--red); }
.stat-value.green { color: var(--green); }

.stat-icon {
  position: absolute;
  right: 16px; top: 50%;
  transform: translateY(-50%);
  font-size: 26px;
  opacity: 0.12;
}

/* ── PANEL ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
}

.panel-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.panel-title .icon {
  width: 26px; height: 26px;
  background: var(--accent-light);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

/* ── TABLE ── */
table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

thead th.num { text-align: right; }

tbody tr {
  border-bottom: 1px solid #f1f2f4;
  transition: background 0.1s;
}

tbody tr:hover { background: #f9fafb; }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 11px 12px;
  font-size: 13.5px;
  vertical-align: middle;
}

tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td a { color: var(--accent); text-decoration: none; font-weight: 500; }
tbody td a:hover { text-decoration: underline; }

/* ── FORM FIELDS ── */
.field { margin-bottom: 14px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:disabled { opacity: 0.5; cursor: not-allowed; background: var(--gray-bg); }
select option { background: #fff; color: var(--text); }
textarea { resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  line-height: 1;
}

.btn:hover {
  background: var(--gray-bg);
  border-color: var(--border-hover);
}

.btn:active { transform: scale(0.98); }

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

.btn-primary:hover {
  background: var(--accent-text);
  border-color: var(--accent-text);
  color: #fff;
}

.btn-sm { padding: 4px 9px; font-size: 12px; }

.btn-danger {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: var(--red);
}
.btn-danger:hover {
  background: #fee2e2;
  border-color: #f87171;
}

.row         { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-draft   { background: var(--gray-bg);  color: var(--text-muted); border: 1px solid var(--gray-border); }
.badge-sent    { background: var(--blue-bg);  color: var(--blue);       border: 1px solid var(--blue-border); }
.badge-paid    { background: var(--green-bg); color: var(--green);      border: 1px solid var(--green-border); }
.badge-overdue { background: var(--red-bg);   color: var(--red);        border: 1px solid var(--red-border); }
.badge-void    { background: var(--gray-bg);  color: var(--text-muted); border: 1px solid var(--gray-border); }

/* ── SAVED ITEM CHIPS ── */
.saved-items-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--accent-light);
  border: 1px solid #ddd6fe;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.saved-items-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.item-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  background: #fff;
  border: 1px solid #c7d2fe;
  border-radius: 99px;
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
}

.item-chip:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chip-rate { font-size: 11px; color: var(--text-muted); }
.item-chip:hover .chip-rate { color: rgba(255,255,255,0.8); }

/* ── ITEMS TABLE (invoice form) ── */
.items-table-wrap { overflow-x: auto; }
.items-table-wrap table { min-width: 560px; }

.i-desc, .i-sub {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 3px 4px;
  border-radius: 4px;
  transition: background 0.1s;
  outline: none;
}

.i-desc:focus, .i-sub:focus { background: var(--accent-light); }

.i-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

.i-sub:focus { color: var(--text-secondary); }

.i-rate, .i-qty {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  text-align: right;
  outline: none;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.i-rate:focus, .i-qty:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79,70,229,0.1);
}

/* ── TOTALS BOX ── */
.totals-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 270px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 13.5px;
}

.total-row + .total-row { border-top: 1px solid #f1f2f4; }

.total-row.final {
  border-top: 1px solid var(--border) !important;
  margin-top: 4px;
  padding-top: 12px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.total-label { color: var(--text-muted); }
.total-value { font-variant-numeric: tabular-nums; font-weight: 500; }

/* ── STATUS BAR ── */
.status-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── FILTER BAR ── */
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-bar select { width: auto; min-width: 140px; cursor: pointer; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--text);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  animation: toastIn 0.25s cubic-bezier(0.34,1.56,0.64,1) both;
  max-width: 320px;
}

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

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon  { font-size: 36px; margin-bottom: 10px; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state-sub   { font-size: 13px; }

/* ── MISC ── */
.muted    { color: var(--text-muted); }
.text-dim { color: var(--text-secondary); }

hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: var(--gray-bg);
  padding: 2px 5px;
  border-radius: 4px;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
  .topbar { padding: 0 16px; }
  .container { padding: calc(var(--topbar-h) + 20px) 16px 36px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .panel { padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
