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

/* ═══════════ VARIABLES ═══════════ */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #1e40af;
  --brand-dark: #1e3a8a;
  --brand-light: #dbeafe;
  --danger: #dc2626;
  --success: #059669;
  --radius: 12px;
}

/* ═══════════ RESET ═══════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  line-height: 1.5;
}

/* ═══════════ LAYOUT ═══════════ */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }

/* ═══════════ TOPBAR ═══════════ */
.topbar {
  background: var(--brand-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.brand { font-size: 17px; font-weight: 800; letter-spacing: .8px; white-space: nowrap; }
.nav { display: flex; flex-wrap: wrap; gap: 6px; }
.nav a {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  transition: all .15s;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.12); }

/* ═══════════ CARDS ═══════════ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

/* ═══════════ TYPOGRAPHY ═══════════ */
h1 { font-size: 22px; font-weight: 800; margin-bottom: 16px; letter-spacing: -.3px; }
h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
h3 { font-size: 16px; font-weight: 700; color: var(--brand-dark); margin: 20px 0 10px; }
.section-title { margin-bottom: 12px; }

/* ═══════════ GRID ═══════════ */
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 600px) { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }

/* ═══════════ FORMS ═══════════ */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px;
  font-size: 16px; /* 16px prevents iOS zoom */
  background: #fff;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(30,64,175,.12); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ═══════════ BUTTONS ═══════════ */
.actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.actions-wrap { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-primary, .btn-secondary, .btn-danger, .btn-outline {
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  transition: all .15s;
  min-height: 44px; /* touch target */
  text-align: center;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #f1f5f9; color: #334155; border: 1px solid #e2e8f0; }
.btn-secondary:hover { background: #e2e8f0; }
.btn-outline { background: #fff; color: var(--brand-dark); border: 1px solid #cbd5e1; }
.btn-outline:hover { background: #f8fafc; }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; min-width: 44px; }

/* ═══════════ TABLES ═══════════ */
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { padding: 10px 8px; font-size: 13px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { background: #f8fafc; font-weight: 600; color: #475569; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; position: sticky; top: 0; }
.table tbody tr:hover { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Mobile responsive table - items form */
.items-cards { display: none; }
@media (max-width: 640px) {
  .items-table-wrap { display: none; }
  .items-cards { display: flex; flex-direction: column; gap: 12px; }
  .item-card {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    position: relative;
  }
  .item-card .item-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .item-card .item-name-field { grid-column: 1 / -1; }
  .item-card .item-remove {
    position: absolute; top: 8px; right: 8px;
    background: #fee2e2; color: var(--danger); border: none; border-radius: 6px;
    width: 32px; height: 32px; font-size: 16px; cursor: pointer;
  }
}

/* ═══════════ PRINT DOC STYLES ═══════════ */
.print-toolbar { margin-bottom: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.doc { /* the printed invoice section */ }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.client-brand { display: flex; align-items: flex-start; gap: 14px; }
.logo { width: 64px; height: 64px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--line); padding: 6px; }
.brand-lg { font-size: 24px; font-weight: 900; color: var(--brand-dark); letter-spacing: -.5px; }
.requisites { font-size: 12px; color: #475569; line-height: 1.6; text-align: right; }

.meta-grid { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 16px 0; background: #f8fafc; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); font-size: 14px; }
@media (min-width: 600px) { .meta-grid { grid-template-columns: 1fr 1fr; } }
.meta-grid .full { grid-column: 1 / -1; }
.meta-grid b { color: var(--text); font-weight: 600; margin-right: 6px; }

.print-table th { background: #e2e8f0; color: #1e293b; border-bottom: 2px solid #cbd5e1; }
.print-table td { border-bottom: 1px solid #e2e8f0; }

/* Print table mobile scroll */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }

/* ═══════════ TOTALS ═══════════ */
.totals { margin-top: 20px; margin-left: auto; max-width: 340px; width: 100%; background: #f8fafc; border-radius: var(--radius); padding: 14px 18px; border: 1px solid var(--line); }
.totals > div { display: flex; justify-content: space-between; padding: 6px 0; color: #334155; font-size: 14px; }
.total-final {
  margin-top: 6px;
  padding-top: 10px !important;
  border-top: 2px solid var(--brand-dark);
  font-size: 20px !important;
  font-weight: 900;
  color: var(--text) !important;
}

/* ═══════════ BADGES ═══════════ */
.badge { display: inline-block; padding: 5px 10px; border-radius: 6px; font-weight: 700; font-size: 11px; letter-spacing: .5px; text-transform: uppercase; }
.no-vat { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badges-row { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.cash-badge { background: var(--brand-light); color: var(--brand-dark); }

/* ═══════════ STATUS CARDS ═══════════ */
.success-card { border-color: #86efac; background: #f0fdf4; }
.success-title { color: #065f46; font-weight: 800; font-size: 20px; }
.success-meta { color: #065f46; margin-top: 4px; font-size: 14px; }
.note { margin-top: 16px; padding: 14px; background: #f0fdf4; border: 1px solid #86efac; border-radius: 8px; color: #065f46; font-size: 13px; font-weight: 500; line-height: 1.5; }
.error-card { border-color: #fecaca; background: #fef2f2; }
.muted { color: var(--muted); }

/* ═══════════ SIGNATURES ═══════════ */
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 48px; padding-top: 20px; }
@media (max-width: 500px) { .signatures { grid-template-columns: 1fr; gap: 24px; } }
.sig-line { border-bottom: 1px solid #334155; margin-top: 36px; }
.sig-label { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

/* ═══════════ RESPONSIVE HELPERS ═══════════ */
@media (max-width: 640px) {
  .container { padding: 10px; }
  .card { padding: 14px; border-radius: 10px; }
  h1 { font-size: 19px; }
  .doc-head { flex-direction: column; }
  .requisites { text-align: left; }
  .brand-lg { font-size: 20px; }
  .totals { max-width: 100%; }
  .actions, .actions-wrap { flex-direction: column; }
  .btn-primary, .btn-secondary, .btn-outline, .btn-danger { width: 100%; }
  .print-toolbar { flex-direction: column; }
}

/* Registry table scroll on mobile */
@media (max-width: 900px) {
  .registry-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .registry-scroll .table { min-width: 700px; }
}

/* ═══════════ PRINT ═══════════ */
@media print {
  .no-print, .topbar, .print-toolbar { display: none !important; }
  .container { max-width: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11px; }
  .card { box-shadow: none; border: none; padding: 0; margin: 0; }
  .meta-grid { background: none; border: none; padding: 8px 0; margin: 12px 0; border-top: 1px solid #000; border-bottom: 1px solid #000; border-radius: 0; }
  .print-table th { background: #eee !important; color: #000 !important; border: 1px solid #999; }
  .print-table td { border: 1px solid #ccc; }
  .totals { background: none; border: none; padding: 0; }
  .total-final { border-top: 2px solid #000 !important; color: #000 !important; }
  .signatures { margin-top: 40px; }
}
