/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --teal:        #1D9E75;
  --teal-light:  #E1F5EE;
  --teal-dark:   #085041;
  --amber:       #BA7517;
  --amber-light: #FAEEDA;
  --red:         #A32D2D;
  --red-light:   #FCEBEB;
  --green:       #3B6D11;
  --green-light: #EAF3DE;
  --blue-light:  #E6F1FB;
  --blue:        #185FA5;
  --sidebar-w:   220px;
  --header-h:    52px;
  --radius:      8px;
  --radius-lg:   12px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; background: #f5f5f3; color: #1a1a1a; }

/* ── PIN Screen ── */
#pin-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh; gap: 24px; background: #f5f5f3;
}
.pin-logo { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: #1a1a1a; }
.pin-logo i { color: var(--teal); font-size: 26px; }
.pin-card {
  background: white; border: 1px solid #e5e5e3; border-radius: var(--radius-lg);
  padding: 2rem; width: 300px; display: flex; flex-direction: column;
  align-items: center; gap: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.pin-label { font-size: 13px; color: #666; }
.pin-hint { font-size: 12px; color: #999; }
.pin-dots { display: flex; gap: 14px; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; background: #f0f0ee; border: 1px solid #d0d0ce; transition: background 0.15s; }
.pin-dot.filled { background: var(--teal); border-color: var(--teal); }
.pin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.pin-btn {
  background: #f5f5f3; border: 1px solid #e5e5e3; border-radius: var(--radius);
  padding: 16px; font-size: 20px; font-weight: 500; cursor: pointer; color: #1a1a1a;
  transition: background 0.1s; font-family: inherit;
}
.pin-btn:hover { background: #e8e8e6; }
.pin-btn:active { transform: scale(0.95); }
.pin-error { font-size: 12px; color: var(--red); min-height: 16px; text-align: center; }

/* ── Main App ── */
#main { display: none; flex-direction: column; height: 100vh; }
#main.visible { display: flex; }

/* ── Header ── */
.header {
  height: var(--header-h); background: white; border-bottom: 1px solid #e5e5e3;
  display: flex; align-items: center; padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
}
.header-logo { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: #1a1a1a; white-space: nowrap; }
.header-logo i { color: var(--teal); font-size: 20px; }
.header-company { font-size: 13px; color: #888; padding-left: 14px; border-left: 1px solid #e5e5e3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-spacer { flex: 1; }
.header-fy { font-size: 12px; color: #999; white-space: nowrap; }
.header-user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #666; cursor: pointer; white-space: nowrap; padding: 6px 10px; border-radius: var(--radius); transition: background 0.1s; }
.header-user:hover { background: #f5f5f3; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--teal-light); color: var(--teal-dark); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }

/* ── Body Layout ── */
.body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
.sidebar { width: var(--sidebar-w); background: white; border-right: 1px solid #e5e5e3; padding: 12px 0; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex-shrink: 0; }
.nav-section { padding: 10px 18px 4px; font-size: 10px; font-weight: 600; color: #aaa; letter-spacing: 0.06em; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 9px 18px; font-size: 13px; color: #666; cursor: pointer; border-left: 2px solid transparent; transition: all 0.12s; user-select: none; }
.nav-item i { font-size: 16px; flex-shrink: 0; }
.nav-item:hover { background: #f5f5f3; color: #1a1a1a; }
.nav-item.active { background: var(--teal-light); color: var(--teal-dark); border-left-color: var(--teal); font-weight: 500; }

/* ── Content ── */
.content { flex: 1; padding: 24px; overflow-y: auto; min-width: 0; }
.page { display: none; max-width: 1100px; }
.page.active { display: block; }
.page-title { font-size: 20px; font-weight: 600; margin-bottom: 18px; }
.page-subtitle { font-size: 13px; color: #888; margin-bottom: 20px; line-height: 1.5; }

/* ── Metrics ── */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.metric { background: white; border: 1px solid #e5e5e3; border-radius: var(--radius-lg); padding: 16px; }
.metric-label { font-size: 11px; color: #999; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500; }
.metric-value { font-size: 24px; font-weight: 600; line-height: 1; }
.metric-sub { font-size: 11px; color: #aaa; margin-top: 4px; }
.metric-value.green { color: var(--green); }
.metric-value.amber { color: var(--amber); }
.metric-value.red { color: var(--red); }

/* ── Cards ── */
.card { background: white; border: 1px solid #e5e5e3; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 16px; }
.card-header { padding: 12px 18px; border-bottom: 1px solid #e5e5e3; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 13px; font-weight: 600; }
.card-meta { font-size: 12px; color: #999; }
.card-body { padding: 16px 18px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 500px; }
th { text-align: left; padding: 9px 18px; font-size: 11px; font-weight: 600; color: #999; text-transform: uppercase; letter-spacing: 0.05em; background: #fafaf8; border-bottom: 1px solid #e5e5e3; white-space: nowrap; }
td { padding: 11px 18px; font-size: 13px; border-bottom: 1px solid #f0f0ee; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafaf8; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 500; white-space: nowrap; }
.badge.paid        { background: var(--green-light); color: var(--green); }
.badge.pending     { background: var(--amber-light); color: var(--amber); }
.badge.overdue     { background: var(--red-light);   color: var(--red); }
.badge.reconciled  { background: var(--teal-light);  color: var(--teal-dark); }
.badge.unreconciled{ background: var(--amber-light); color: var(--amber); }
.badge.credit      { background: var(--green-light); color: var(--green); }
.badge.debit       { background: #f5f5f3;            color: #666; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border-radius: var(--radius); font-size: 13px; cursor: pointer;
  border: 1px solid #d5d5d3; background: white; color: #1a1a1a;
  font-family: inherit; transition: all 0.1s; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: #f5f5f3; border-color: #c0c0be; }
.btn:active { transform: scale(0.98); }
.btn i { font-size: 14px; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: white; }
.btn.primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.btn.danger { color: var(--red); border-color: #f0c0c0; }
.btn.danger:hover { background: var(--red-light); }
.btn.icon-btn { padding: 6px 8px; border-color: transparent; background: transparent; color: #999; }
.btn.icon-btn:hover { background: #f5f5f3; color: #333; }

/* ── Forms ── */
.form-body { padding: 16px 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; color: #666; font-weight: 500; }
.form-actions { display: flex; gap: 8px; margin-top: 6px; }
input[type="text"], input[type="email"], input[type="number"], input[type="date"],
input[type="password"], select, textarea {
  font-size: 13px; font-family: inherit; width: 100%;
  border: 1px solid #d5d5d3; border-radius: var(--radius);
  padding: 8px 10px; color: #1a1a1a; background: white;
  transition: border-color 0.15s; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(29,158,117,0.1); }
textarea { resize: vertical; }
.filter-select { width: auto; min-width: 130px; }
.pin-change-error { font-size: 12px; color: var(--red); min-height: 16px; }

/* ── Toolbar ── */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar-spacer { flex: 1; }

/* ── Reconcile ── */
.recon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 0; }
.recon-col-title { font-size: 12px; font-weight: 600; margin-bottom: 8px; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
.recon-sel-item { padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f0f0ee; transition: background 0.1s; }
.recon-sel-item:last-child { border-bottom: none; }
.recon-sel-item:hover { background: #fafaf8; }
.recon-sel-item.selected { background: var(--teal-light); }
.recon-sel-item .name  { font-size: 13px; font-weight: 500; }
.recon-sel-item .detail{ font-size: 11px; color: #999; margin-top: 2px; }
.recon-sel-item .amount{ font-size: 14px; font-weight: 600; margin-top: 4px; }
.recon-confirm-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-bottom: 16px; }
.recon-item-box { background: var(--teal-light); border: 1px solid var(--teal); border-radius: var(--radius); padding: 12px; }
.recon-item-box .name  { font-size: 12px; font-weight: 600; color: var(--teal-dark); }
.recon-item-box .detail{ font-size: 11px; color: #666; margin-top: 2px; }
.recon-item-box .amount{ font-size: 14px; font-weight: 600; margin-top: 4px; }
.recon-arrow { color: var(--teal); font-size: 22px; text-align: center; }
.recon-warning { background: var(--amber-light); border: 1px solid #e5c080; border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: #7a5a10; margin-bottom: 14px; }
.recon-empty { padding: 28px; text-align: center; color: #bbb; font-size: 13px; }

/* ── Reports ── */
.reports-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.reports-grid .full-width { grid-column: 1 / -1; }
.report-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid #f0f0ee; font-size: 13px; }
.report-row:last-child { border-bottom: none; }
.report-row span:first-child { color: #888; }
.report-row span:last-child { font-weight: 600; }
.progress-bar-bg { background: #f0f0ee; border-radius: 4px; height: 8px; overflow: hidden; margin: 10px 0 6px; }
.progress-bar    { background: var(--teal); height: 100%; border-radius: 4px; transition: width 0.4s; }
.gst-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.gst-item .label { font-size: 11px; color: #999; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-bottom: 4px; }
.gst-item .value { font-size: 20px; font-weight: 600; }
.gst-item .sub   { font-size: 11px; color: #bbb; margin-top: 2px; }
.client-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.client-bar-name { width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #666; }
.client-bar-bg   { flex: 1; background: #f0f0ee; border-radius: 4px; height: 10px; overflow: hidden; }
.client-bar-fill { background: var(--teal); height: 100%; border-radius: 4px; }
.client-bar-val  { width: 80px; text-align: right; font-weight: 600; color: var(--green); }

/* ── Export ── */
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.export-card { background: white; border: 1px solid #e5e5e3; border-radius: var(--radius-lg); padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.export-icon { width: 44px; height: 44px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.export-icon.xlsx { background: var(--green-light); color: var(--green); }
.export-icon.csv  { background: var(--blue-light);  color: var(--blue); }
.export-title { font-size: 15px; font-weight: 600; }
.export-desc  { font-size: 13px; color: #888; line-height: 1.5; }
.export-items { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.export-items li { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #666; }
.export-items li i { font-size: 14px; color: var(--teal); flex-shrink: 0; }
.export-btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Settings ── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.settings-grid .card:first-child { grid-column: 1 / -1; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--teal-dark); color: white; padding: 11px 18px;
  border-radius: var(--radius); font-size: 13px; font-weight: 500;
  display: none; align-items: center; gap: 8px; z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .reports-grid, .export-grid, .settings-grid { grid-template-columns: 1fr; }
  .reports-grid .full-width { grid-column: 1; }
  .settings-grid .card:first-child { grid-column: 1; }
  .recon-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .gst-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
}

/* ── CSV Import ── */
.csv-info { background: var(--teal-light); border: 1px solid var(--teal); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: var(--teal-dark); margin-bottom: 12px; }
.csv-error { background: var(--red-light); border: 1px solid #e0a0a0; border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: var(--red); margin-top: 10px; }
.csv-help { font-size: 12px; color: #999; margin-top: 14px; padding-top: 12px; border-top: 1px solid #f0f0ee; line-height: 1.8; }
.csv-skip-cb { width: 16px; height: 16px; cursor: pointer; accent-color: var(--teal); }
tr.csv-skipped td { opacity: 0.4; text-decoration: line-through; }

/* ── Mobile nav ── */
.mob-menu-btn { display:none; background:none; border:none; cursor:pointer; padding:6px; color:#1a1a1a; }
.mob-menu-btn i { font-size:22px; }
.sidebar-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.4); z-index:200; }
.sidebar-overlay.visible { display:block; }

@media (max-width: 640px) {
  .mob-menu-btn { display:flex; align-items:center; order:-1; }
  .header { padding:0 12px; gap:8px; }
  .header-logo { font-size:14px; }
  .header-logo i { font-size:16px; }
  .header-company { display:none; }
  .header-fy { display:none; }
  .header-user span { display:none; }
  .header-user i { display:none; }
  .avatar { width:32px; height:32px; cursor:pointer; }

  .sidebar {
    position:fixed; left:-260px; top:0; bottom:0; width:240px;
    z-index:300; transition:left 0.25s ease; box-shadow:none;
  }
  .sidebar.open {
    left:0; box-shadow:4px 0 24px rgba(0,0,0,0.18);
  }

  .body { overflow:hidden; }
  .content { padding:14px; width:100%; overflow-x:hidden; }

  .metrics { grid-template-columns:1fr 1fr; gap:8px; }
  .metric { padding:12px; }
  .metric-value { font-size:18px; }

  .page-title { font-size:16px; margin-bottom:12px; }
  .table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  th { font-size:10px; padding:7px 10px; }
  td { font-size:12px; padding:8px 10px; }

  .recon-confirm-grid { grid-template-columns:1fr; }
  .recon-arrow { transform:rotate(90deg); margin:0 auto; }
  .recon-grid { grid-template-columns:1fr; }

  .export-grid { grid-template-columns:1fr; }
  .settings-grid { grid-template-columns:1fr; }
  .settings-grid .card:first-child { grid-column:1; }
  .reports-grid { grid-template-columns:1fr; }
  .reports-grid .full-width { grid-column:1; }
  .gst-grid { grid-template-columns:1fr; }

  .form-row { grid-template-columns:1fr; }
  .toolbar { gap:6px; flex-wrap:wrap; }
  .btn { padding:7px 10px; font-size:12px; }
  .card-header { flex-wrap:wrap; gap:6px; }
}

/* ── Bottom nav (mobile only) ── */
.bottom-nav {
  display:none; position:fixed; bottom:0; left:0; right:0;
  background:white; border-top:1px solid #e5e5e3;
  z-index:150; padding:0 0 env(safe-area-inset-bottom,0);
}
.bottom-nav-item {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:3px; padding:8px 4px; cursor:pointer; color:#999;
  font-size:10px; font-weight:500; flex:1; transition:color 0.1s;
  -webkit-tap-highlight-color:transparent;
}
.bottom-nav-item i { font-size:20px; }
.bottom-nav-item.active { color:var(--teal); }
.bottom-nav-item:active { opacity:0.7; }

@media (max-width: 640px) {
  .bottom-nav { display:flex; }
  #main { padding-bottom:60px; }
  .content { padding-bottom:20px; }
}
