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

:root {
  --dark:    #0d0d1a;
  --dark2:   #1a0a2e;
  --orange:  #e8773a;
  --purple:  #b44fc8;
  --grad:    linear-gradient(90deg, #e8773a, #b44fc8);
  --bg:      #f0f2f7;
  --card:    #ffffff;
  --border:  #eaeaf0;
  --text:    #1a1a2e;
  --muted:   #5a5a7a;
  --light:   #fafafe;
  --sidebar: 240px;
}

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

body { font-family:'Inter',sans-serif; background:var(--bg); color:var(--text); font-size:14px; display:flex; min-height:100vh; }

/* ── SIDEBAR ── */
.sidebar {
  width:var(--sidebar); background:var(--dark); position:fixed; top:0; left:0; height:100vh;
  display:flex; flex-direction:column; z-index:100; overflow:hidden;
}
.sidebar::before {
  content:''; position:absolute; top:-60px; left:-40px; width:200px; height:200px;
  background:radial-gradient(circle,rgba(120,40,200,.4) 0%,transparent 70%); border-radius:50%;
}
.sidebar::after {
  content:''; position:absolute; bottom:-40px; right:-40px; width:180px; height:180px;
  background:radial-gradient(circle,rgba(160,60,20,.3) 0%,transparent 70%); border-radius:50%;
}
.sidebar-logo { padding:28px 24px 20px; display:flex; align-items:center; gap:10px; position:relative; z-index:2; }
.sidebar-logo img { height:40px; }
.sidebar-logo span { font-size:18px; font-weight:700; background:var(--grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }

.sidebar-nav { flex:1; padding:8px 12px; position:relative; z-index:2; overflow-y:auto; }
.nav-section { font-size:9px; text-transform:uppercase; letter-spacing:1.8px; color:#4a4a6a; font-weight:600; padding:16px 12px 6px; }
.nav-item {
  display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:10px;
  cursor:pointer; color:#9a9ab8; font-size:13px; font-weight:500; transition:.15s; margin-bottom:2px;
}
.nav-item:hover { background:rgba(255,255,255,.06); color:#fff; }
.nav-item.active { background:rgba(232,119,58,.15); color:#e8773a; }
.nav-item .icon { font-size:16px; width:20px; text-align:center; }

.sidebar-footer { padding:16px 12px; border-top:1px solid rgba(255,255,255,.06); position:relative; z-index:2; }
.sidebar-footer p { font-size:11px; color:#4a4a6a; line-height:1.6; }

/* ── MAIN ── */
.main { margin-left:var(--sidebar); flex:1; display:flex; flex-direction:column; min-height:100vh; }

.topbar {
  background:#fff; border-bottom:1px solid var(--border); padding:0 32px;
  height:64px; display:flex; align-items:center; justify-content:space-between;
  position:sticky; top:0; z-index:50;
}
.topbar h1 { font-size:18px; font-weight:700; color:var(--text); }
.topbar-actions { display:flex; gap:10px; align-items:center; }

.content { padding:28px 32px; flex:1; }

/* ── CARDS ── */
.card { background:var(--card); border-radius:14px; border:1px solid var(--border); padding:24px; }
.card-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; }
.card-title { font-size:13px; font-weight:700; text-transform:uppercase; letter-spacing:1.2px; color:var(--muted); }

/* ── STAT CARDS ── */
.stats-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:24px; }
.stat-card { background:var(--card); border-radius:14px; border:1px solid var(--border); padding:20px 24px; }
.stat-card .label { font-size:11px; text-transform:uppercase; letter-spacing:1.5px; color:var(--muted); font-weight:600; margin-bottom:8px; }
.stat-card .value { font-size:26px; font-weight:800; color:var(--text); line-height:1; }
.stat-card .value.grad { background:var(--grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }
.stat-card .sub { font-size:11px; color:var(--muted); margin-top:6px; }
.stat-card .icon { font-size:28px; margin-bottom:8px; }

/* ── BUTTONS ── */
.btn { display:inline-flex; align-items:center; gap:6px; padding:9px 18px; border-radius:8px; font-family:'Inter',sans-serif; font-size:13px; font-weight:600; cursor:pointer; border:none; transition:.15s; text-decoration:none; }
.btn-primary { background:var(--grad); color:#fff; }
.btn-primary:hover { opacity:.9; }
.btn-ghost  { background:transparent; color:var(--muted); border:1px solid var(--border); }
.btn-ghost:hover { background:var(--light); color:var(--text); }
.btn-danger { background:#fee2e2; color:#dc2626; border:1px solid #fecaca; }
.btn-danger:hover { background:#fecaca; }
.btn-sm { padding:6px 12px; font-size:12px; }
.btn-icon { padding:8px; border-radius:8px; background:var(--light); border:1px solid var(--border); color:var(--muted); cursor:pointer; font-size:14px; display:inline-flex; align-items:center; justify-content:center; transition:.15s; }
.btn-icon:hover { background:var(--border); color:var(--text); }

/* ── STATUS BADGES ── */
.badge { display:inline-flex; align-items:center; padding:3px 10px; border-radius:20px; font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.8px; }
.badge-borrador { background:#f1f5f9; color:#64748b; }
.badge-enviada  { background:#dbeafe; color:#1d4ed8; }
.badge-pagada   { background:#dcfce7; color:#166534; }
.badge-vencida  { background:#fee2e2; color:#dc2626; }

/* ── TABLE ── */
.table-wrap { overflow-x:auto; }
table.main-table { width:100%; border-collapse:collapse; }
table.main-table thead th { padding:10px 16px; text-align:left; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:1px; color:var(--muted); border-bottom:2px solid var(--border); white-space:nowrap; }
table.main-table tbody tr { border-bottom:1px solid var(--border); transition:.1s; }
table.main-table tbody tr:hover { background:var(--light); }
table.main-table tbody td { padding:12px 16px; font-size:13.5px; }
table.main-table .col-actions { text-align:right; white-space:nowrap; }
table.main-table .amount { font-weight:700; text-align:right; }

/* ── FILTERS ── */
.filters { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:16px; }
.search-wrap { position:relative; flex:1; min-width:200px; }
.search-wrap input { width:100%; padding:9px 14px 9px 36px; border:1px solid var(--border); border-radius:8px; font-family:'Inter',sans-serif; font-size:13px; background:#fff; outline:none; }
.search-wrap input:focus { border-color:#b44fc8; }
.search-wrap::before { content:'🔍'; position:absolute; left:11px; top:50%; transform:translateY(-50%); font-size:13px; }
select.filter-select { padding:9px 14px; border:1px solid var(--border); border-radius:8px; font-family:'Inter',sans-serif; font-size:13px; background:#fff; outline:none; cursor:pointer; }
select.filter-select:focus { border-color:#b44fc8; }

/* ── MODAL ── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.5); z-index:200; display:flex; align-items:center; justify-content:center; padding:20px; }
.modal-overlay.hidden { display:none; }
.modal { background:#fff; border-radius:16px; width:100%; max-width:780px; max-height:90vh; overflow-y:auto; display:flex; flex-direction:column; }
.modal-header { padding:24px 28px 0; display:flex; justify-content:space-between; align-items:center; }
.modal-header h2 { font-size:18px; font-weight:700; }
.modal-close { background:none; border:none; font-size:22px; cursor:pointer; color:var(--muted); line-height:1; }
.modal-body { padding:24px 28px; }
.modal-footer { padding:0 28px 24px; display:flex; gap:10px; justify-content:flex-end; border-top:1px solid var(--border); padding-top:16px; }

/* ── FORM ── */
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.form-group { display:flex; flex-direction:column; gap:6px; }
.form-group.full { grid-column:1/-1; }
label { font-size:12px; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:.8px; }
input[type=text], input[type=email], input[type=number], input[type=date], select, textarea {
  padding:10px 14px; border:1px solid var(--border); border-radius:8px;
  font-family:'Inter',sans-serif; font-size:13.5px; color:var(--text); background:#fff; outline:none; transition:.15s;
}
input:focus, select:focus, textarea:focus { border-color:#b44fc8; }
textarea { resize:vertical; min-height:80px; }

/* ── ITEMS TABLE (factura editor) ── */
.items-table { width:100%; border-collapse:collapse; margin-bottom:10px; }
.items-table thead th { background:#0d0d1a; color:#fff; padding:10px 12px; font-size:11px; text-align:left; }
.items-table thead th.r { text-align:right; }
.items-table tbody td { padding:6px 4px; vertical-align:middle; }
.items-table input { border:1px solid var(--border); border-radius:6px; padding:7px 10px; width:100%; font-size:13px; }
.items-table input:focus { border-color:#b44fc8; }
.item-total { text-align:right; font-weight:600; min-width:80px; font-size:13.5px; padding-right:8px; }

/* ── TOTALS SIDEBAR ── */
.totals-box { background:var(--light); border:1px solid var(--border); border-radius:12px; padding:16px 20px; }
.totals-box .row { display:flex; justify-content:space-between; padding:5px 0; font-size:13.5px; color:var(--muted); border-bottom:1px solid var(--border); }
.totals-box .row:last-child { border-bottom:none; }
.totals-box .row.final { font-size:16px; font-weight:800; color:var(--text); padding-top:10px; }
.totals-box .row.final span:last-child { background:var(--grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }

/* ── EMPTY STATE ── */
.empty { text-align:center; padding:60px 20px; color:var(--muted); }
.empty .icon { font-size:48px; margin-bottom:12px; }
.empty h3 { font-size:18px; font-weight:600; margin-bottom:6px; color:var(--text); }

/* ── ALERTS ── */
.alert { position:fixed; top:20px; right:20px; z-index:9999; padding:14px 20px; border-radius:10px; font-size:13px; font-weight:600; box-shadow:0 4px 20px rgba(0,0,0,.15); display:flex; align-items:center; gap:8px; animation:slideIn .2s ease; }
.alert-success { background:#dcfce7; color:#166534; }
.alert-error   { background:#fee2e2; color:#dc2626; }
@keyframes slideIn { from{transform:translateX(100%);opacity:0} to{transform:translateX(0);opacity:1} }

/* ── CLIENT SELECTOR ── */
.client-dropdown { position:relative; }
.client-results { position:absolute; top:100%; left:0; right:0; background:#fff; border:1px solid var(--border); border-radius:8px; box-shadow:0 8px 24px rgba(0,0,0,.1); z-index:10; max-height:200px; overflow-y:auto; }
.client-result-item { padding:10px 14px; cursor:pointer; font-size:13px; }
.client-result-item:hover { background:var(--light); }
.client-result-item .name { font-weight:600; }
.client-result-item .email { font-size:11px; color:var(--muted); }

/* ── RESPONSIVE ── */
@media (max-width:900px) {
  .stats-grid { grid-template-columns:1fr 1fr; }
  .form-grid  { grid-template-columns:1fr; }
}
