/* =========================================================
   TalNet Computers - Invoicing System
   Professional, responsive UI
   ========================================================= */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0891b2;
  --info-soft: #cffafe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.10);
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 700; color: #111827; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
p { margin: 0 0 1em; }
.muted, .text-muted { color: var(--text-muted); }

/* ---------------- App layout ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 40;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: grid; place-items: center;
  font-weight: 800; color: #fff; letter-spacing: .5px;
}
.brand-logo {
  border-radius: 10px; object-fit: contain;
  background: #fff; border: 1px solid var(--border); padding: 2px;
}
.brand-text strong { display: block; font-size: 16px; line-height: 1.1; }
.brand-text span { font-size: 12px; color: #94a3b8; }

.sidebar-nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.07); }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin-bottom: 4px;
  border-radius: 9px; color: #cbd5e1;
  font-weight: 500; transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 6px 16px rgba(37,99,235,.35); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-overlay { display: none; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-right { margin-left: auto; }
.menu-toggle { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--text); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.user-name { font-weight: 600; }

.content { padding: 24px; flex: 1; max-width: 1280px; width: 100%; margin: 0 auto; }
.footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 16px 24px; color: var(--text-muted); font-size: 12px;
  border-top: 1px solid var(--border); background: var(--surface);
}

/* ---------------- Cards & stats ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; }
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::after {
  content: ''; position: absolute; right: -20px; top: -20px;
  width: 80px; height: 80px; border-radius: 50%; background: var(--primary-soft); opacity: .6;
}
.stat .label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 6px; color: #111827; position: relative; }
.stat .sub { font-size: 12px; margin-top: 4px; position: relative; }
.stat.accent-green .value { color: var(--success); }
.stat.accent-blue .value { color: var(--primary); }
.stat.accent-amber .value { color: var(--warning); }
.stat.accent-red .value { color: var(--danger); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
  font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background .15s, box-shadow .15s, transform .05s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 6px 16px rgba(37,99,235,.3); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; padding: 11px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
}
table.data th, table.data td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th {
  background: #f8fafc; color: var(--text-muted); font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
table.data tbody tr:hover { background: #f9fafb; }
table.data td.actions { white-space: nowrap; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-draft { background: #e5e7eb; color: #374151; }
.badge-sent { background: var(--info-soft); color: var(--info); }
.badge-paid { background: var(--success-soft); color: var(--success); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-cancelled { background: #f3f4f6; color: #9ca3af; }

/* ---------------- Alerts ---------------- */
.alert {
  padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; font-weight: 500;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: #166534; border-color: #bbf7d0; }
.alert-danger { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--info-soft); color: #0e7490; border-color: #a5f3fc; }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field.full { grid-column: 1 / -1; }
label { font-weight: 600; font-size: 13px; color: #374151; }
input, select, textarea {
  font-family: inherit; font-size: 14px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--text);
  width: 100%; transition: border-color .15s, box-shadow .15s;
}
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 42px; }
.pwd-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  border: 0; background: transparent; cursor: pointer; font-size: 16px;
  line-height: 1; padding: 4px; color: var(--text-muted);
}
.pwd-toggle:hover { color: var(--text); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.form-actions { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; }

/* ---------------- Toolbar ---------------- */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar .spacer { flex: 1; }
.search-input { max-width: 280px; position: relative; }
.search-input input { padding-left: 34px; }
.search-input::before {
  content: '🔍'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: .6;
}

/* ---------------- Invoice line items ---------------- */
.items-table th, .items-table td { padding: 8px 10px; }
.items-table input { padding: 7px 9px; }
.items-table .line-total { font-weight: 700; white-space: nowrap; text-align: right; }
.totals-box { margin-left: auto; width: 320px; max-width: 100%; margin-top: 16px; }
.totals-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.totals-row.grand { font-size: 18px; font-weight: 800; border-bottom: 0; color: #111827; }
.totals-row .t-label { color: var(--text-muted); }

/* ---------------- Auth ---------------- */
.auth-body {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 16px;
  padding: 32px; box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-brand h1 { font-size: 20px; margin: 0; }
.auth-brand p { margin: 0; color: var(--text-muted); font-size: 13px; }
.auth-hint { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 16px; }

/* ---------------- Invoice print view ---------------- */
.invoice-doc { background: #fff; border-radius: var(--radius); padding: 40px; box-shadow: var(--shadow); }

/* Centered, attractive invoice header */
.invoice-header { text-align: center; padding-bottom: 22px; margin-bottom: 26px; border-bottom: 3px solid var(--primary); position: relative; }
.invoice-header::after { content: ''; position: absolute; left: 50%; bottom: -3px; transform: translateX(-50%); width: 130px; height: 3px; background: linear-gradient(90deg, #38bdf8, #2563eb); }
.invoice-logo { margin: 0 auto 12px; width: 64px; height: 64px; }
.invoice-logo img, .invoice-logo .brand-mark { margin: 0 auto; }
.invoice-co-name { font-size: 26px; letter-spacing: .3px; margin: 0 0 2px; }
.invoice-co-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-size: 12.5px; margin-top: 10px; }
.invoice-co-meta span { position: relative; }
.invoice-co-meta span + span::before { content: '·'; position: absolute; left: -10px; color: var(--text-muted); }

.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 26px; }
.party-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.party-box .ptitle { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #fff; background: var(--primary); display: inline-block; padding: 3px 12px; border-radius: 6px; margin-bottom: 12px; }
.invoice-from .inv-no { font-size: 17px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.invoice-from .k { color: var(--text-muted); display: inline-block; min-width: 86px; }
.pay-status { margin-top: 16px; }

/* ---------------- Empty state ---------------- */
.empty {
  text-align: center; padding: 48px 16px; color: var(--text-muted);
}
.empty .big { font-size: 40px; margin-bottom: 8px; }

.row-actions a, .row-actions button {
  font-size: 12px; padding: 5px 10px; border-radius: 7px; margin-right: 4px;
  border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text);
}
.row-actions a:hover, .row-actions button:hover { background: #f1f5f9; }
.row-actions .del:hover { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }

/* Colored icon action buttons */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: 15px; line-height: 1; text-decoration: none;
  border: 1px solid transparent; cursor: pointer; transition: transform .05s, box-shadow .15s, background .15s;
}
.icon-btn:active { transform: translateY(1px); }
.icon-view { background: #eff6ff; color: #2563eb; }
.icon-view:hover { background: #dbeafe; }
.icon-edit { background: #fffbeb; color: #d97706; }
.icon-edit:hover { background: #fef3c7; }
.icon-print { background: #ecfdf5; color: #059669; }
.icon-print:hover { background: #d1fae5; }
.icon-delete { background: #fef2f2; color: #dc2626; }
.icon-delete:hover { background: #fee2e2; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mb-16 { margin-bottom: 16px; } .mt-16 { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.no-print { }

/* ---------------- Responsive ---------------- */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .invoice-parties { grid-template-columns: 1fr; }
  .topbar-title { font-size: 15px; }
  .user-name { display: none; }
  .invoice-doc { padding: 20px; }
}

/* ---------------- Print ---------------- */
body.printing .sidebar,
body.printing .topbar,
body.printing .footer,
body.printing .toolbar,
body.printing .no-print,
body.printing .sidebar-overlay { display: none !important; }
body.printing .main { margin-left: 0; }
body.printing .content { padding: 0; max-width: 100%; }
body.printing .invoice-doc { box-shadow: none; border-radius: 0; }

@media print {
  .sidebar, .topbar, .footer, .no-print, .sidebar-overlay { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; max-width: 100%; }
  .invoice-doc { box-shadow: none; border-radius: 0; }
  body { background: #fff; }
}
