/* ============================================================
   Personal Accounting — Modern SaaS UI with proper contrast
   ============================================================ */
:root {
  --primary:       #4f46e5;
  --primary-dark:  #4338ca;
  --primary-light: #eef2ff;
  --primary-mid:   #6366f1;
  --success:       #059669;
  --success-light: #ecfdf5;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;
  --warning:       #d97706;
  --warning-light: #fffbeb;
  --info:          #0891b2;

  /* ── Background & surface ── */
  --bg:          #eef0f5;          /* soft blue-grey — clearly not white */
  --bg-inner:    #f2f4f8;          /* inner content areas */
  --surface:     #ffffff;          /* cards, forms */
  --surface-alt: #f8f9fc;          /* table rows alt, input bg */

  /* ── Borders ── */
  --border:      #d1d5db;          /* stronger than before */
  --border-light:#e5e7eb;
  --border-focus:#6366f1;

  /* ── Text ── */
  --text:        #0f172a;
  --text-mid:    #374151;
  --text-muted:  #6b7280;
  --text-light:  #9ca3af;

  /* ── Sidebar ── */
  --sidebar-w:   240px;
  --topbar-h:    60px;

  /* ── Shape ── */
  --radius:      10px;
  --radius-sm:   7px;

  /* ── Shadows — deeper for contrast ── */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.07);
  --shadow:      0 2px 6px rgba(0,0,0,0.09), 0 1px 3px rgba(0,0,0,0.07);
  --shadow-md:   0 4px 14px rgba(0,0,0,0.11), 0 2px 6px rgba(0,0,0,0.07);
  --shadow-lg:   0 10px 40px rgba(0,0,0,0.14);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ══════════════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════════════ */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ══════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: #1e1b4b;
  display: flex; flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto; overflow-x: hidden;
  box-shadow: 2px 0 12px rgba(0,0,0,0.18);
  z-index: 10;
}
.sidebar-brand {
  padding: 22px 20px 18px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 6px;
}
.brand-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg,#6366f1,#8b5cf6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,102,241,0.45);
}
.brand-text { font-size: 15px; font-weight: 700; color: #fff; }
.brand-sub  { font-size: 11px; color: rgba(255,255,255,0.38); margin-top: 1px; }

.sidebar-nav { padding: 6px 12px 24px; flex: 1; }
.nav-section {
  padding: 18px 8px 5px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 1.3px; color: rgba(255,255,255,0.28);
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500;
  color: rgba(255,255,255,0.58);
  transition: all 0.15s; margin-bottom: 2px;
}
.nav-item:hover  { background: rgba(255,255,255,0.09); color: #fff; text-decoration: none; }
.nav-item.active { background: linear-gradient(135deg,#6366f1,#4f46e5); color: #fff; box-shadow: 0 4px 12px rgba(99,102,241,0.38); }
.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; opacity: 0.75; }
.nav-item.active .nav-icon, .nav-item:hover .nav-icon { opacity: 1; }
.nav-logout { color: rgba(248,113,113,0.75); margin-top: 4px; }
.nav-logout:hover { background: rgba(220,38,38,0.15); color: #f87171; }

/* ══════════════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════════════ */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.07);
  z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-mid);
  background: var(--surface-alt);
  padding: 6px 14px 6px 8px;
  border-radius: 24px; border: 1px solid var(--border);
}
.user-avatar {
  width: 28px; height: 28px;
  background: linear-gradient(135deg,#6366f1,#8b5cf6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
}
.content-area { flex: 1; overflow-y: auto; padding: 28px 32px; background: var(--bg); }

/* ══════════════════════════════════════════════════
   CARDS — clearly raised from bg
══════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-alt);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-header h2 {
  font-size: 13.5px; font-weight: 700;
  color: var(--text); letter-spacing: 0.1px;
}
.card-body { padding: 20px; }

/* ══════════════════════════════════════════════════
   STAT CARDS
══════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card::before {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-mid));
}
.stat-card.success::before { background: linear-gradient(90deg,#059669,#10b981); }
.stat-card.danger::before  { background: linear-gradient(90deg,#dc2626,#ef4444); }
.stat-card.warning::before { background: linear-gradient(90deg,#d97706,#f59e0b); }
.stat-card.info::before    { background: linear-gradient(90deg,#0891b2,#06b6d4); }
.stat-icon {
  width: 40px; height: 40px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; margin-bottom: 13px;
  background: var(--primary-light);
}
.stat-card.success .stat-icon { background: var(--success-light); }
.stat-card.danger  .stat-icon { background: var(--danger-light); }
.stat-card.warning .stat-icon { background: var(--warning-light); }
.stat-label { font-size: 11.5px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700; margin-bottom: 6px; }
.stat-value { font-size: 25px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.stat-card.danger .stat-value  { color: var(--danger); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.warning .stat-value { color: var(--warning); }

/* ══════════════════════════════════════════════════
   TABLES
══════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: #f0f2f8;            /* tinted — clearly not white */
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-mid);
  padding: 11px 16px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle; font-size: 13.5px;
  color: var(--text);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) td { background: #f8f9fc; }
tbody tr:hover td { background: #f0f2ff; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ══════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all 0.15s;
  white-space: nowrap; letter-spacing: 0.1px;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg,#4f46e5,#6366f1);
  color: white; box-shadow: 0 4px 12px rgba(79,70,229,0.32);
}
.btn-primary:hover { color: white; box-shadow: 0 6px 18px rgba(79,70,229,0.42); }
.btn-success {
  background: linear-gradient(135deg,#059669,#10b981);
  color: white; box-shadow: 0 4px 12px rgba(5,150,105,0.3);
}
.btn-success:hover { color: white; }
.btn-danger {
  background: linear-gradient(135deg,#dc2626,#ef4444);
  color: white; box-shadow: 0 3px 10px rgba(220,38,38,0.28);
}
.btn-danger:hover { color: white; }
.btn-warning { background: linear-gradient(135deg,#d97706,#f59e0b); color: white; }
.btn-warning:hover { color: white; }
.btn-secondary {
  background: #f1f3f8; color: var(--text-mid);
  border: 1.5px solid var(--border); font-weight: 600;
}
.btn-secondary:hover { background: #e4e7f0; color: var(--text); transform: none; }
.btn-outline {
  background: white; color: var(--text-mid);
  border: 1.5px solid var(--border); font-weight: 500;
}
.btn-outline:hover { background: var(--surface-alt); border-color: #adb5d0; color: var(--text); transform: none; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-sm:hover { transform: none; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════════════════
   FORMS & INPUTS — visible on bright monitors
══════════════════════════════════════════════════ */
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
.form-full   { grid-column: 1 / -1; }
.form-group  { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 12.5px; font-weight: 700;
  color: var(--text-mid); letter-spacing: 0.1px;
}
.form-control {
  padding: 9px 13px;
  border: 1.5px solid #c4c9d8;    /* stronger border — visible on white bg */
  border-radius: 8px;
  font-size: 14px; color: var(--text);
  background: #fbfcff;             /* very slightly tinted, not pure white */
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  width: 100%;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
.form-control:hover:not(:focus) { border-color: #a0a8c0; }
textarea.form-control { resize: vertical; min-height: 76px; }
select.form-control   { cursor: pointer; }

/* ══════════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.badge::before { content: '●'; font-size: 7px; }
.badge-paid, .badge-accepted   { background: #d1fae5; color: #065f46; }
.badge-unpaid, .badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-partial                 { background: #fef3c7; color: #78350f; }
.badge-cancelled, .badge-draft { background: #f3f4f6; color: #4b5563; border: 1px solid #e5e7eb; }
.badge-sent                    { background: #dbeafe; color: #1e40af; }
.badge-converted               { background: #ede9fe; color: #5b21b6; }

/* ══════════════════════════════════════════════════
   LINE ITEMS TABLE
══════════════════════════════════════════════════ */
.line-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.line-table th {
  background: #f0f2f8;
  padding: 10px 10px;
  text-align: left; font-size: 11px; font-weight: 700;
  color: var(--text-mid); border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.line-table td { padding: 7px 8px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.line-table input {
  padding: 7px 10px;
  border: 1.5px solid #c4c9d8;
  border-radius: 6px; font-size: 13px;
  background: #fbfcff;
  transition: border 0.15s;
  font-family: inherit;
}
.line-table input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 2px rgba(79,70,229,0.1); }
.line-table input[type=number] { text-align: right; }
.line-table .line-total-cell { text-align: right; font-weight: 700; min-width: 90px; color: var(--text); }
.remove-line-btn {
  background: none; border: none; color: #c4c9d8;
  cursor: pointer; font-size: 17px; padding: 3px 7px; border-radius: 5px; transition: all 0.15s;
}
.remove-line-btn:hover { background: #fee2e2; color: var(--danger); }

/* ══════════════════════════════════════════════════
   TOTALS BOX — clearly separated
══════════════════════════════════════════════════ */
.totals-box {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 22px;
  min-width: 290px;
  box-shadow: var(--shadow-sm);
}
.totals-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; color: var(--text-mid); }
.totals-row span:last-child { font-weight: 600; color: var(--text); }
.totals-row.grand {
  font-size: 16px; font-weight: 800; color: var(--primary);
  border-top: 2px solid var(--primary);
  margin-top: 10px; padding-top: 12px;
}
.totals-right { display: flex; justify-content: flex-end; margin-top: 16px; }

/* ══════════════════════════════════════════════════
   ALERTS
══════════════════════════════════════════════════ */
.alert {
  padding: 13px 18px; border-radius: var(--radius);
  margin-bottom: 18px; font-size: 13.5px;
  border-left: 4px solid; display: flex; align-items: center; gap: 10px;
}
.alert-success { background: #f0fdf4; color: #065f46; border-color: var(--success); }
.alert-error,.alert-danger { background: var(--danger-light); color: #991b1b; border-color: var(--danger); }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #3b82f6; }
.alert-warning { background: var(--warning-light); color: #78350f; border-color: var(--warning); }

/* ══════════════════════════════════════════════════
   ACTION ROW
══════════════════════════════════════════════════ */
.action-row { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }

/* ══════════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg,#1e1b4b 0%,#312e81 50%,#4f46e5 100%);
}
.login-box {
  background: white; border-radius: 16px;
  padding: 44px 40px; width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  width: 52px; height: 52px;
  background: linear-gradient(135deg,#4f46e5,#8b5cf6);
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 26px; margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(79,70,229,0.3);
}
.login-box h1 { font-size: 24px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-light); font-size: 13.5px; margin-bottom: 32px; }
.login-box .form-group { margin-bottom: 18px; }

/* ══════════════════════════════════════════════════
   DOC VIEW
══════════════════════════════════════════════════ */
.doc-view { max-width: 900px; }
.divider { border: none; border-top: 1px solid var(--border-light); margin: 20px 0; }

/* ══════════════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════════════ */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.mt-1{margin-top:8px}.mt-2{margin-top:16px}.mt-3{margin-top:24px}
.mb-1{margin-bottom:8px}.mb-2{margin-bottom:16px}.mb-3{margin-bottom:24px}
.empty-state { text-align: center; padding: 56px 16px; color: var(--text-light); }
.empty-state .icon { font-size: 44px; margin-bottom: 12px; opacity: 0.4; display: block; }
.empty-state p { font-size: 14px; }
.tag { display: inline-block; padding: 2px 8px; background: var(--surface-alt); border-radius: 4px; font-size: 12px; color: var(--text-muted); border: 1px solid var(--border-light); }

/* ══════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { width: 68px; }
  .brand-text,.brand-sub,.nav-section,.nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .form-grid,.form-grid-3 { grid-template-columns: 1fr; }
  .content-area { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ══════════════════════════════════════════════════
   RESPONSIVE — Tablet, Mobile, POS, Touch Screens
══════════════════════════════════════════════════ */

/* Touch-friendly base — bigger tap targets everywhere */
@media (hover: none), (pointer: coarse) {
  .btn { min-height: 44px; padding: 10px 18px; }
  .btn-sm { min-height: 38px; padding: 8px 14px; }
  .nav-item { min-height: 44px; }
  .form-control { min-height: 44px; font-size: 16px; } /* 16px prevents iOS zoom */
  select.form-control { min-height: 44px; }
  textarea.form-control { font-size: 16px; }
  tbody td { padding: 14px 16px; }
  .remove-line-btn { min-width: 36px; min-height: 36px; font-size: 20px; }
  input[type=checkbox] { width: 20px; height: 20px; }
}

/* ── Tablet (768px - 1024px) ── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .content-area { padding: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile (max 768px) ── */
@media (max-width: 768px) {
  :root { --topbar-h: 56px; }

  /* Sidebar becomes bottom nav on mobile */
  .layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
    padding: 0;
  }

  .sidebar-brand { display: none; }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    padding: 0;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }

  .nav-section { display: none; }

  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 8px 12px;
    min-width: 64px;
    font-size: 10px;
    border-radius: 0;
    margin: 0;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    color: rgba(255,255,255,0.6);
  }
  .nav-item.active {
    background: rgba(99,102,241,0.3);
    box-shadow: none;
    border-top: 2px solid #6366f1;
  }
  .nav-icon { font-size: 20px; width: auto; height: auto; }
  .nav-item span:not(.nav-icon) { display: block; font-size: 9px; line-height: 1; }
  .nav-logout { color: rgba(248,113,113,0.8); }

  .main-content {
    margin-bottom: 72px; /* space for bottom nav */
    overflow: auto;
    height: 100vh;
  }

  .content-area { padding: 12px; }

  .topbar {
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .topbar-title { font-size: 15px; }

  /* Cards */
  .card { margin-bottom: 12px; border-radius: 8px; }
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 14px; }

  /* Stats - single column on small mobile */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 20px; }

  /* Forms */
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; gap: 12px; }
  .form-full { grid-column: 1; }

  /* Tables - horizontal scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }
  thead th { font-size: 10px; padding: 9px 10px; white-space: nowrap; }
  tbody td { padding: 11px 10px; font-size: 13px; }

  /* Buttons */
  .action-row { gap: 6px; flex-wrap: wrap; }
  .btn { font-size: 13px; padding: 9px 14px; }
  .btn-group { flex-wrap: wrap; }

  /* Totals box */
  .totals-box { min-width: 100%; }
  .totals-right { justify-content: stretch; }

  /* Line items table */
  .line-table { min-width: 600px; }

  /* Doc view */
  .doc-view { max-width: 100%; }
}

/* ── Small mobile (max 480px) ── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-user .user-avatar ~ * { display: none; } /* hide username, show only avatar */
}

/* ══════════════════════════════════════════════════
   POS / TOUCH SCREEN specific improvements
══════════════════════════════════════════════════ */
.touch-scroll { -webkit-overflow-scrolling: touch; overflow-y: auto; }

/* Larger checkboxes for touch */
.line-vat { width: 20px !important; height: 20px !important; cursor: pointer; }

/* Prevent text selection on buttons (POS) */
.btn, .nav-item { user-select: none; -webkit-user-select: none; }

/* Active state feedback for touch */
.btn:active { transform: scale(0.97); opacity: 0.85; }
.nav-item:active { opacity: 0.7; }

