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

:root {
  --navy: #2A357F;
  --navy-dark: #1f2963;
  --bg: #f4f5f9;
  --card-bg: #ffffff;
  --border: #e3e5ee;
  --text: #1c1e2b;
  --text-light: #6b6f85;
  --green: #1e9e5a;
  --yellow: #c88a00;
  --red: #cf3a3a;
  --gray: #8a8d9c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

/* ===== LOGIN / SETUP ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  padding: 20px;
}

.auth-card {
  background: #fff;
  padding: 44px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}

.auth-card h1 {
  font-size: 22px;
  margin-bottom: 6px;
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
  font-weight: 700;
}

.auth-logo {
  max-width: 220px;
  max-height: 90px;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto 6px;
}

.auth-card p.subtitle {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 28px;
}

.auth-card form { text-align: left; }

.field { margin-bottom: 8px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
}

.btn {
  display: inline-block;
  background: var(--navy);
  color: #fff !important;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
}

.btn:hover { background: var(--navy-dark); }

.btn-secondary { background: #eceef5; color: var(--text) !important; }
.btn-secondary:hover { background: #dfe2ee; }

.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b32e2e; }

.btn-block { width: 100%; }

.error-msg {
  background: #fdecec;
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 18px;
  text-align: left;
}

.success-msg {
  background: #e8f8ef;
  color: var(--green);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 18px;
  text-align: left;
}

/* ===== APP SHELL ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 26px 0;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
}

.sidebar-logo {
  max-width: 100%;
  max-height: 56px;
  width: auto;
  height: auto;
  display: block;
}

.sidebar-nav { display: flex; flex-direction: column; flex: 1; gap: 4px; }

.sidebar-nav a {
  padding: 12px 14px;
  margin: 0 14px;
  border-radius: 12px;
  font-size: 14px;
  color: rgba(255,255,255,0.75);
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.1); color: #fff; }

.sidebar-nav a.active {
  background: #fff;
  color: var(--navy);
  font-weight: 700;
}

.sidebar-footer {
  padding: 16px 24px 0;
  border-top: 1px solid rgba(255,255,255,0.15);
  margin-top: 12px;
}

.sidebar-user { font-size: 13px; opacity: 0.85; margin-bottom: 8px; }
.sidebar-logout { font-size: 13px; color: #ffd2d2; background: none; border: none; cursor: pointer; padding: 0; }

.main-content { flex: 1; padding: 20px 40px; max-width: 1200px; display: flex; flex-direction: column; min-height: 100vh; }
.card-fill { flex: 1; display: flex; flex-direction: column; }
.card-fill form { flex: 1; display: flex; flex-direction: column; }
.card-fill .form-grid { row-gap: 10px; }
.card-fill form .btn { margin-top: auto; align-self: flex-start; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 { font-size: 24px; margin: 0; font-weight: 700; }

/* ===== CARDS / STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 30px; }

.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.stat-card .label { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.stat-card .value { font-size: 24px; font-weight: 700; }

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }

/* ===== TABLE ===== */
table { width: 100%; border-collapse: collapse; background: var(--card-bg); }

table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-light);
  padding: 12px 16px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}

table td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
table tr:hover td { background: #fafafe; }

.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.table-wrap table { min-width: 640px; }

.actions-cell { text-align: right; white-space: nowrap; }
.actions-cell a { margin-left: 10px; font-size: 13px; font-weight: 600; }
.actions-cell .link-danger { color: var(--red); }
.actions-cell .link-edit { color: var(--navy); }

/* ===== BADGES ===== */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-paid { background: #e8f8ef; color: var(--green); }
.badge-pending { background: #fff6e0; color: var(--yellow); }
.badge-overdue { background: #fdecec; color: var(--red); }
.badge-cancelled { background: #eceef2; color: var(--gray); }

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }

.items-table th, .items-table td { padding: 8px; }
.items-table input { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-family: 'Poppins', 'Segoe UI', Arial, sans-serif; }
.items-table .qty-input, .items-table .price-input { width: 90px; }
.items-table .remove-row { color: var(--red); cursor: pointer; font-weight: 700; }

.totals-box { max-width: 320px; margin-left: auto; margin-top: 16px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14px; }
.totals-box .row.total { font-size: 18px; font-weight: 700; border-top: 2px solid var(--border); margin-top: 6px; padding-top: 12px; }

/* ===== INVOICE / DOCUMENT VIEW / PRINT ===== */
.invoice-doc { background: #fff; padding: 50px; border: 1px solid var(--border); border-radius: 12px; }
.invoice-doc-header { display: flex; justify-content: space-between; margin-bottom: 40px; }
.invoice-logo { max-height: 70px; width: auto; height: auto; display: block; margin-bottom: 10px; }
.invoice-company-info { font-size: 13px; color: var(--text-light); line-height: 1.5; }
.invoice-meta { text-align: right; font-size: 14px; color: var(--text-light); }
.invoice-parties { display: flex; justify-content: space-between; margin-bottom: 30px; }
.invoice-parties .block { max-width: 45%; }
.invoice-parties h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; color: var(--text-light); }
.invoice-actions { display: flex; gap: 10px; margin-bottom: 20px; }

/* ===== ICON BUTTONS (small view/delete actions in tables) ===== */
.icon-btn {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:30px;
  height:30px;
  border-radius:7px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--navy);
  cursor:pointer;
  vertical-align:middle;
}
.icon-btn:hover { background:#f4f5f9; }
.icon-btn.danger { color:var(--red); border-color:#f3c9c9; }
.icon-btn.danger:hover { background:#fdecec; }
.icon-btn.disabled { color:var(--gray); cursor:default; opacity:0.5; pointer-events:none; }
.actions-cell .icon-btn { margin-left:6px; }
.actions-cell .icon-btn:first-child { margin-left:0; }
.text-center { text-align:center; }

/* ===== TOPBAR (redesigned dashboard header) ===== */
.topbar {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  margin-bottom:28px;
  flex-wrap:wrap;
}
.topbar-user { display:flex; align-items:center; gap:12px; }
.avatar-circle {
  width:44px; height:44px; border-radius:50%;
  background:var(--navy); color:#fff;
  display:flex; align-items:center; justify-content:center;
  font-weight:700; font-size:16px; flex-shrink:0;
}
.topbar-user-info .name { font-weight:600; font-size:14px; }
.topbar-user-info .sub { font-size:12px; color:var(--text-light); }
.topbar-search { flex:1; max-width:360px; position:relative; }
.topbar-search svg { position:absolute; left:14px; top:50%; transform:translateY(-50%); color:var(--text-light); pointer-events:none; }
.topbar-search input {
  width:100%; padding:11px 16px 11px 40px; border-radius:999px;
  border:1px solid var(--border); background:#fff;
  font-family:'Poppins','Segoe UI',Arial,sans-serif; font-size:13px;
}
.topbar-icon-btn {
  width:44px; height:44px; border-radius:50%;
  background:#fff; border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center;
  color:var(--navy); position:relative; flex-shrink:0;
}
.topbar-icon-btn .dot {
  position:absolute; top:9px; right:10px; width:8px; height:8px;
  border-radius:50%; background:var(--red); border:2px solid #fff;
}

/* ===== BENTO STAT CARDS ===== */
.bento-grid { display:grid; grid-template-columns:repeat(4, 1fr); gap:12px; margin-bottom:10px; }
.bento-card { position:relative; background:var(--card-bg); border:1px solid var(--border); border-radius:20px; padding:16px; }
.bento-card.dark { background:var(--navy); border:none; color:#fff; }
.bento-card-row { display:flex; align-items:center; gap:14px; }
.bento-card-icon {
  width:50px; height:50px; border-radius:50%;
  background:var(--bg); display:flex; align-items:center; justify-content:center; color:var(--navy); flex-shrink:0;
}
.bento-card.dark .bento-card-icon { background:rgba(255,255,255,0.14); color:#fff; }
.bento-card-title { font-size:14px; font-weight:600; color:var(--text-light); margin-bottom:2px; }
.bento-card.dark .bento-card-title { color:rgba(255,255,255,0.75); }
.bento-value { font-size:30px; font-weight:700; line-height:1.1; }
.badge-pill { position:absolute; top:14px; right:14px; display:inline-block; font-size:12px; font-weight:700; padding:3px 11px; border-radius:999px; background:#e8f8ef; color:var(--green); }
.badge-pill.neutral { background:rgba(255,255,255,0.16); color:#fff; }

@media (max-width: 900px) {
  .bento-grid { grid-template-columns:1fr 1fr; }
  .topbar-search { display:none; }
}

/* ===== SIGNATURE PAD (specific to this app) ===== */
.sig-canvas { border: 1px solid var(--border); border-radius: 8px; touch-action: none; width: 100%; background: #fff; }

@media print {
  .sidebar, .invoice-actions, .no-print { display: none !important; }
  .app-shell, .main-content { display: block; padding: 0; margin: 0; }
  .invoice-doc { border: none; padding: 0; }
  body { background: #fff; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 14px 16px; overflow-x: auto; }
  .sidebar-brand { display: none; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main-content { padding: 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .invoice-parties { flex-direction: column; gap: 20px; }
  .invoice-parties .block { max-width: 100%; }
}