/* ============================================================
   JOHN TILES BILLING — Main Stylesheet
   Theme: Clean Blue & White, Professional
   Font: Plus Jakarta Sans + Space Mono
   ============================================================ */

:root {
  --blue-900: #0c1e3e;
  --blue-800: #0f2a55;
  --blue-700: #1a3a6e;
  --blue-600: #1e4d9b;
  --blue-500: #2563eb;
  --blue-400: #3b82f6;
  --blue-300: #93c5fd;
  --blue-100: #dbeafe;
  --blue-50:  #eff6ff;

  --white:    #ffffff;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;

  --green:    #16a34a;
  --green-bg: #dcfce7;
  --red:      #dc2626;
  --red-bg:   #fee2e2;
  --amber:    #d97706;
  --amber-bg: #fef3c7;

  --sidebar-w: 250px;
  --radius:    10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }

/* ============================================================
   LAYOUT
   ============================================================ */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--blue-900);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon {
  width: 40px; height: 40px;
  background: var(--blue-500);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.brand-name {
  font-size: .95rem;
  font-weight: 800;
  color: var(--white);
  letter-spacing: .01em;
}
.brand-sub {
  font-size: .7rem;
  color: var(--blue-300);
  margin-top: .1rem;
  font-family: 'Space Mono', monospace;
  letter-spacing: .05em;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.nav-section {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--blue-300);
  padding: .9rem .5rem .3rem;
  opacity: .7;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .75rem;
  border-radius: 8px;
  font-size: .83rem;
  font-weight: 500;
  color: rgba(255,255,255,.65);
  transition: background .15s, color .15s;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: var(--white);
}
.nav-item.active {
  background: var(--blue-600);
  color: var(--white);
  font-weight: 600;
}
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 1rem .75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip {
  display: flex; align-items: center; gap: .6rem;
  margin-bottom: .75rem;
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--blue-500);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-name  { font-size: .8rem; font-weight: 600; color: #fff; }
.user-role  { font-size: .68rem; color: var(--blue-300); }
.btn-logout {
  display: block;
  text-align: center;
  padding: .45rem;
  border-radius: 7px;
  background: rgba(220,38,38,.15);
  color: #fca5a5;
  font-size: .8rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(220,38,38,.3); }

/* ---- Main ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}
.page-body {
  padding: 2rem;
  max-width: 1200px;
}

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.page-title {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--gray-900);
  letter-spacing: -.02em;
}
.page-sub {
  font-size: .82rem;
  color: var(--gray-500);
  margin-top: .2rem;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  padding: 1.5rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
}

/* ---- Stat cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-icon.blue   { background: var(--blue-50); }
.stat-icon.green  { background: var(--green-bg); }
.stat-icon.amber  { background: var(--amber-bg); }
.stat-icon.red    { background: var(--red-bg); }
.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: 'Space Mono', monospace;
  color: var(--gray-900);
  line-height: 1;
}
.stat-label {
  font-size: .77rem;
  color: var(--gray-500);
  margin-top: .25rem;
  font-weight: 500;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .52rem 1.1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: .83rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  line-height: 1.4;
  white-space: nowrap;
}
.btn-primary {
  background: var(--blue-500);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-600); }
.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-200); }
.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover { background: #15803d; }
.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }
.btn-sm {
  padding: .32rem .7rem;
  font-size: .77rem;
  border-radius: 6px;
}
.btn-icon { padding: .4rem .5rem; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--blue-400);
  color: var(--blue-500);
}
.btn-outline:hover { background: var(--blue-50); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
thead th {
  background: var(--blue-900);
  color: rgba(255,255,255,.85);
  padding: .75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
thead th:first-child { border-radius: var(--radius) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius) 0 0; }
tbody td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
  color: var(--gray-700);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--blue-50); }
tbody tr.low-stock td { background: #fff0f0 !important; color: var(--red); }
tbody tr.low-stock:hover td { background: #fde0e0 !important; }

.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
}
.badge-red    { background: var(--red-bg);   color: var(--red); }
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-blue   { background: var(--blue-100); color: var(--blue-600); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }

/* ============================================================
   FORMS
   ============================================================ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-700);
}
.form-control {
  padding: .58rem .85rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-family: inherit;
  font-size: .88rem;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
select.form-control { cursor: pointer; }
.form-control::placeholder { color: var(--gray-400); }
.form-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.alert-success {
  background: var(--green-bg);
  color: #166534;
  border: 1px solid #bbf7d0;
}
.alert-success::before { content: '✅'; }
.alert-error {
  background: var(--red-bg);
  color: #991b1b;
  border: 1px solid #fecaca;
}
.alert-error::before { content: '❌'; }
.alert-warning {
  background: var(--amber-bg);
  color: #92400e;
  border: 1px solid #fde68a;
}
.alert-warning::before { content: '⚠️'; }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--blue-900) 0%, var(--blue-700) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.auth-card {
  background: var(--white);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.auth-logo-icon {
  width: 60px; height: 60px;
  background: var(--blue-500);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  margin: 0 auto .75rem;
}
.auth-logo h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--gray-900);
}
.auth-logo p {
  font-size: .82rem;
  color: var(--gray-500);
  margin-top: .2rem;
}
.auth-card .form-group { margin-bottom: .85rem; }
.auth-link {
  text-align: center;
  margin-top: 1.2rem;
  font-size: .83rem;
  color: var(--gray-500);
}
.auth-link a { color: var(--blue-500); font-weight: 600; }

/* ============================================================
   INVOICE CREATE — item rows
   ============================================================ */
#items-table thead th { font-size: .72rem; padding: .6rem .7rem; }
#items-table tbody td { padding: .5rem .5rem; }
#items-table .form-control { padding: .42rem .6rem; font-size: .83rem; }
.totals-box {
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  min-width: 280px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: .88rem;
  padding: .3rem 0;
  color: var(--gray-700);
}
.totals-row.total-final {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--blue-700);
  border-top: 2px solid var(--blue-200);
  padding-top: .65rem;
  margin-top: .4rem;
}
.mono { font-family: 'Space Mono', monospace; }

/* ============================================================
   PRINT INVOICE
   ============================================================ */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-area {
    display: block !important;
    position: static;
    box-shadow: none;
    padding: 0;
  }
  .sidebar, .main-content > *:not(.print-area) { display: none; }
}

.print-invoice {
  max-width: 780px;
  margin: 0 auto;
  background: #fff;
  padding: 2rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}
.print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 3px solid var(--blue-500);
}
.print-company h2 { font-size: 1.6rem; font-weight: 800; color: var(--blue-900); }
.print-company p  { font-size: .83rem; color: var(--gray-500); margin-top: .2rem; }
.print-invoice-meta { text-align: right; }
.print-invoice-meta .inv-num {
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue-700);
  font-family: 'Space Mono', monospace;
}
.print-invoice-meta p { font-size: .82rem; color: var(--gray-500); margin-top: .2rem; }
.print-customer {
  background: var(--blue-50);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex; gap: 2rem; flex-wrap: wrap;
}
.print-customer dt { font-size: .72rem; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .06em; }
.print-customer dd { font-size: .92rem; font-weight: 600; color: var(--gray-900); margin-top: .15rem; }
.print-totals {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.25rem;
}
.print-totals-inner { min-width: 240px; }
.print-total-row {
  display: flex; justify-content: space-between;
  font-size: .88rem;
  padding: .3rem 0;
  color: var(--gray-700);
}
.print-total-row.grand {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--blue-800);
  border-top: 2px solid var(--blue-200);
  margin-top: .35rem;
  padding-top: .55rem;
}
.print-footer {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
  font-size: .78rem;
  color: var(--gray-400);
}

/* ============================================================
   MISC
   ============================================================ */
.flex   { display: flex; }
.gap-1  { gap: .5rem; }
.gap-2  { gap: 1rem; }
.mt-1   { margin-top: .5rem; }
.mt-2   { margin-top: 1rem; }
.mb-2   { margin-bottom: 1rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: .82rem; }
.text-muted { color: var(--gray-400); }
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 1.5rem 0; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { font-size: .9rem; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .page-body { padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
