/* Factura IWC — Ibiza Work Center branding */
:root {
  --brand: #F15A24;
  --brand-hover: #d94e1c;
  --brand-soft: rgba(241, 90, 36, 0.12);
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --muted: #6b7280;
  --line: #e8e8e8;
  --bg: #f6f5f3;
  --card: #ffffff;
  --success: #0d9488;
  --success-bg: #ccfbf1;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
  --sidebar-w: 260px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
img { max-width: 100%; height: auto; }
h1,h2,h3 { margin: 0 0 .5rem; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
p { margin: 0 0 1rem; color: var(--ink-soft); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 4px;
}
.sidebar-brand .brand-text { line-height: 1.2; }
.sidebar-brand .brand-text strong { display: block; font-size: .95rem; color: #fff; }
.sidebar-brand .brand-text span { font-size: .7rem; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .06em; }
.sidebar-nav { padding: 1rem .75rem; flex: 1; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .65rem .85rem;
  border-radius: 8px;
  color: rgba(255,255,255,.75);
  font-weight: 500;
  margin-bottom: .2rem;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--brand); color: #fff; }
.sidebar-nav .nav-section {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: 1rem .85rem .4rem;
}
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .75rem;
  color: rgba(255,255,255,.45);
}
.sidebar-footer a { color: rgba(255,255,255,.7); }
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .user-meta { text-align: right; font-size: .85rem; }
.topbar .user-meta strong { display: block; color: var(--ink); }
.topbar .user-meta span { color: var(--muted); font-size: .75rem; }
.content { padding: 1.5rem; flex: 1; }
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-header p { margin: 0; }

/* Guest layout */
.guest-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(241,90,36,.15), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(26,26,26,.06), transparent 45%),
    var(--bg);
}
.guest-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem;
  border: 1px solid var(--line);
}
.guest-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.guest-logo img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 6px;
}
.guest-logo h1 { font-size: 1.35rem; margin-top: .75rem; }
.guest-logo p { font-size: .85rem; margin: 0; }

/* Cards & stats */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-title { font-size: 1rem; margin-bottom: 1rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}
.stat .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: .25rem; color: var(--ink); }
.stat .value.accent { color: var(--brand); }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: .35rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="url"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { min-height: 90px; resize: vertical; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.25rem;
  align-items: center;
}
.help { font-size: .75rem; color: var(--muted); margin-top: .25rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: .875rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--bg); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
table.data th,
table.data td {
  text-align: left;
  padding: .7rem .75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  background: #fafafa;
}
table.data tr:hover td { background: #fafafa; }
table.data .actions { white-space: nowrap; text-align: right; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-muted { background: #f3f4f6; color: #4b5563; }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

/* Alerts */
.alerts { margin-bottom: 1rem; }
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: .5rem;
  font-size: .9rem;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: #115e59; border-color: #99f6e4; }
.alert-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--info-bg); color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: var(--warn-bg); color: #92400e; border-color: #fde68a; }

/* Empty state */
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}
.empty strong { display: block; color: var(--ink); margin-bottom: .35rem; }

/* Invoice items editor */
.items-editor table { width: 100%; }
.items-editor th { font-size: .7rem; }
.items-editor input, .items-editor select { padding: .4rem .5rem; font-size: .85rem; }
.items-editor .col-desc { width: 36%; }
.items-editor .col-qty { width: 10%; }
.items-editor .col-price { width: 14%; }
.items-editor .col-iva, .items-editor .col-irpf { width: 12%; }
.items-editor .col-actions { width: 6%; }

/* Print invoice */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .invoice-print { box-shadow: none; border: none; }
}

.invoice-print {
  max-width: 900px;
  margin: 0 auto;
  background: #fff;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.invoice-print .head {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 3px solid var(--brand);
}
.invoice-print .logo-box img { max-height: 64px; max-width: 180px; object-fit: contain; }
.invoice-print .doc-title { text-align: right; }
.invoice-print .doc-title h1 { color: var(--brand); font-size: 1.75rem; margin: 0; }
.invoice-print .parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.invoice-print .party-box {
  background: #fafafa;
  border-radius: 8px;
  padding: 1rem;
  border: 1px solid var(--line);
}
.invoice-print .party-box h3 {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 .5rem;
}
.invoice-print .party-box strong { display: block; font-size: 1rem; margin-bottom: .25rem; }
.invoice-print .party-box p { margin: 0; font-size: .85rem; color: var(--ink-soft); }
.invoice-print table.items { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.invoice-print table.items th {
  background: var(--ink);
  color: #fff;
  padding: .6rem .75rem;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.invoice-print table.items td {
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
}
.invoice-print .totals {
  margin-left: auto;
  width: 280px;
  margin-top: 1rem;
}
.invoice-print .totals-row {
  display: flex;
  justify-content: space-between;
  padding: .35rem 0;
  font-size: .9rem;
}
.invoice-print .totals-row.grand {
  border-top: 2px solid var(--ink);
  margin-top: .5rem;
  padding-top: .65rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
}
.invoice-print .footer-note {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: .8rem;
  color: var(--muted);
}
.invoice-print .powered {
  margin-top: 1.5rem;
  text-align: center;
  font-size: .7rem;
  color: #9ca3af;
}
.invoice-print .powered img { height: 18px; vertical-align: middle; margin-right: .35rem; opacity: .7; }

/* Setup banner */
.setup-banner {
  background: linear-gradient(135deg, var(--brand-soft), #fff);
  border: 1px solid rgba(241,90,36,.25);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Toolbar search */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.toolbar .search { flex: 1; min-width: 180px; max-width: 320px; }
.toolbar select { max-width: 180px; }

/* Mobile */
.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem .65rem;
  cursor: pointer;
}
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .form-grid { grid-template-columns: 1fr; }
  .invoice-print .parties { grid-template-columns: 1fr; }
  .invoice-print .head { flex-direction: column; }
  .invoice-print .doc-title { text-align: left; }
}
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 30;
}
.overlay.show { display: block; }
