:root {
  --primary: #102f6b;
  --primary-2: #1b5fc1;
  --primary-dark: #061936;
  --accent: #f4b63f;
  --accent-2: #ffdf80;
  --bg: #07152e;
  --card: rgba(255, 255, 255, 0.82);
  --glass: rgba(255, 255, 255, 0.14);
  --text: #142033;
  --muted: #697386;
  --border: rgba(255,255,255,.28);
  --line: rgba(17, 61, 124, 0.11);
  --danger: #b91c1c;
  --success: #047857;
  --warning: #b45309;
  --shadow: 0 28px 70px rgba(2, 13, 34, 0.22);
  --shadow-3d: 0 20px 0 rgba(6, 25, 54, .10), 0 32px 70px rgba(3, 14, 37, .22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 10%, rgba(244, 182, 63, .45), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(61, 138, 255, .55), transparent 30%),
    radial-gradient(circle at 80% 80%, rgba(255, 255, 255, .16), transparent 24%),
    linear-gradient(135deg, #061936 0%, #102f6b 45%, #07152e 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  width: 420px;
  height: 420px;
  border-radius: 42% 58% 48% 52%;
  background: linear-gradient(135deg, rgba(255,255,255,.18), rgba(244,182,63,.22));
  filter: blur(.2px);
  z-index: -1;
  animation: floatBlob 12s ease-in-out infinite;
}
body::before { left: -170px; bottom: -160px; }
body::after { right: -150px; top: 130px; animation-delay: -5s; }
@keyframes floatBlob { 0%,100%{ transform: translate3d(0,0,0) rotate(0deg); } 50%{ transform: translate3d(20px,-28px,0) rotate(12deg); } }

.app-shell {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
  padding: 18px;
  gap: 18px;
  perspective: 1400px;
}

.sidebar {
  color: white;
  padding: 24px 18px;
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 34px;
  background: linear-gradient(160deg, rgba(255,255,255,.18), rgba(255,255,255,.06)), linear-gradient(180deg, rgba(16,47,107,.95), rgba(6,25,54,.94));
  backdrop-filter: blur(18px);
  box-shadow: 16px 22px 65px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.20);
  transform: rotateY(-5deg) translateZ(0);
  transform-origin: left center;
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 28px; }
.logo {
  width: 56px;
  height: 56px;
  border-radius: 20px;
  background: linear-gradient(145deg, #fff0b5, var(--accent));
  color: var(--primary-dark);
  display:flex; align-items:center; justify-content:center;
  font-size: 30px; font-weight: 950;
  box-shadow: 0 12px 0 rgba(103, 69, 0, .20), 0 22px 45px rgba(244,182,63,.34), inset 0 1px 0 rgba(255,255,255,.65);
  transform: rotate(-6deg);
}
.brand h1 { margin: 0; font-size: 25px; letter-spacing: -.03em; }
.brand p { margin: 4px 0 0; opacity: .78; font-size: 13px; }
nav { display: grid; gap: 10px; }
.nav-btn {
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.09);
  color: white;
  padding: 13px 14px;
  border-radius: 17px;
  text-align: left;
  cursor: pointer;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.11), 0 10px 24px rgba(0,0,0,.10);
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}
.nav-btn:hover { transform: translateX(5px) translateY(-2px); background: rgba(255,255,255,.16); }
.nav-btn.active {
  background: linear-gradient(145deg, white, #eef5ff);
  color: var(--primary);
  box-shadow: 0 10px 0 rgba(0,0,0,.11), 0 22px 35px rgba(0,0,0,.18);
  transform: translateX(7px);
}

.main-content {
  padding: 18px;
  border-radius: 34px;
  background: linear-gradient(145deg, rgba(255,255,255,.72), rgba(255,255,255,.38));
  border: 1px solid rgba(255,255,255,.30);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
  padding: 22px;
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255,255,255,.94), rgba(255,255,255,.58));
  border: 1px solid rgba(255,255,255,.55);
  box-shadow: 0 18px 40px rgba(9, 39, 90, .12), inset 0 1px 0 rgba(255,255,255,.8);
}
.eyebrow { margin: 0 0 6px; color: var(--primary-2); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .12em; }
h2 { margin: 0; font-size: 36px; letter-spacing: -.055em; color: var(--primary-dark); }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.page { display: none; animation: liftIn .32s ease; }
.page.active { display: block; }
@keyframes liftIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
.grid { display: grid; gap: 18px; }
.stats { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.card {
  position: relative;
  background: var(--card);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 28px;
  padding: 22px;
  box-shadow: var(--shadow-3d), inset 0 1px 0 rgba(255,255,255,.86);
  backdrop-filter: blur(14px);
  transform-style: preserve-3d;
  transition: transform .22s ease, box-shadow .22s ease;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 12% 0%, rgba(255,255,255,.75), transparent 32%), linear-gradient(135deg, rgba(244,182,63,.12), transparent 38%);
  pointer-events: none;
}
.card:hover { transform: translateY(-6px) rotateX(1.4deg); box-shadow: 0 22px 0 rgba(6,25,54,.08), 0 46px 90px rgba(3,14,37,.22); }
.card > * { position: relative; z-index: 1; }
.stat small { color: var(--muted); font-weight: 900; text-transform: uppercase; letter-spacing: .08em; font-size: 11px; }
.stat strong { display: block; font-size: 31px; margin-top: 10px; color: var(--primary-dark); letter-spacing: -.04em; }
.stat span { display: inline-block; margin-top: 8px; font-size: 13px; color: var(--muted); }
.two-col { grid-template-columns: minmax(330px, 400px) 1fr; align-items: start; }
.form { display: grid; gap: 13px; }
label { font-weight: 850; font-size: 13px; color: #26364d; }
input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid rgba(15, 47, 107, .16);
  border-radius: 16px;
  background: rgba(255,255,255,.88);
  font: inherit;
  outline: none;
  box-shadow: inset 0 2px 8px rgba(9, 39, 90, .04);
}
input:focus, select:focus, textarea:focus { border-color: rgba(27,95,193,.55); box-shadow: 0 0 0 4px rgba(27,95,193,.10); }
textarea { min-height: 88px; resize: vertical; }
button, .import-label {
  border: 0;
  border-radius: 16px;
  padding: 12px 15px;
  font-weight: 900;
  cursor: pointer;
  display:inline-flex; align-items:center; justify-content:center; gap: 8px;
  text-decoration: none;
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}
button:hover, .import-label:hover { transform: translateY(-2px); filter: brightness(1.02); }
button:active, .import-label:active { transform: translateY(1px); }
.primary { background: linear-gradient(145deg, var(--primary-2), var(--primary)); color: white; box-shadow: 0 10px 0 rgba(6,25,54,.18), 0 20px 34px rgba(27,95,193,.25); }
.secondary { background: linear-gradient(145deg, #ffffff, #edf4ff); color: var(--primary); border: 1px solid rgba(16,47,107,.12); box-shadow: 0 8px 0 rgba(6,25,54,.07), 0 16px 24px rgba(9,39,90,.10); }
.danger { background: linear-gradient(145deg, #fff1f1, #fee2e2); color: var(--danger); }
.success { background: linear-gradient(145deg, #f0fff6, #dcfce7); color: var(--success); }
.warning { background: linear-gradient(145deg, #fff9e6, #fef3c7); color: var(--warning); }
.table-wrap { overflow-x: auto; border-radius: 20px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 14px 11px; border-bottom: 1px solid rgba(17,61,124,.10); text-align: left; font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; background: rgba(255,255,255,.34); }
tr:hover td { background: rgba(255,255,255,.34); }
.badge { display:inline-flex; padding: 7px 10px; border-radius: 999px; font-size: 12px; font-weight: 900; background: linear-gradient(145deg,#edf4ff,#fff); color: var(--primary); border: 1px solid rgba(27,95,193,.12); box-shadow: 0 5px 14px rgba(27,95,193,.09); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button { padding: 8px 10px; border-radius: 12px; font-size: 12px; box-shadow: 0 5px 0 rgba(6,25,54,.07), 0 10px 16px rgba(9,39,90,.08); }
.notice { background: rgba(255,247,237,.84); border: 1px solid rgba(254,215,170,.8); color: #9a3412; padding: 14px; border-radius: 18px; margin-bottom: 16px; box-shadow: 0 12px 28px rgba(154,52,18,.08); }
#print-area { display: none; }
#toast { position: fixed; right: 22px; bottom: 22px; background: linear-gradient(145deg, var(--primary), var(--primary-dark)); color: white; padding: 14px 18px; border-radius: 18px; box-shadow: 0 14px 0 rgba(0,0,0,.12), 0 28px 60px rgba(0,0,0,.24); display:none; z-index: 20; }
.document { background:white; width: 760px; padding: 42px; color: #111827; }
.doc-header { display:flex; justify-content:space-between; gap:30px; border-bottom: 3px solid var(--primary); padding-bottom: 18px; margin-bottom: 24px; }
.doc-logo { width: 54px; height: 54px; border-radius: 16px; background: var(--primary); color: white; display:flex; align-items:center; justify-content:center; font-size: 28px; font-weight: 900; }
.doc-title { font-size: 34px; color: var(--primary); margin: 0; text-transform: uppercase; }
.doc-meta { text-align:right; color:#374151; }
.doc-section { margin: 22px 0; }
.doc-table { min-width: 0; }
.doc-total { text-align:right; font-size: 22px; font-weight: 900; margin-top: 20px; }
.doc-footer { margin-top: 45px; padding-top: 18px; border-top: 1px solid #e5e7eb; color:#6b7280; font-size: 13px; }
@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; padding: 10px; }
  .sidebar { height: auto; position: relative; top: 0; transform: none; border-radius: 26px; }
  nav { grid-template-columns: repeat(2, 1fr); }
  .two-col, .stats { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; border-radius: 24px; }
  h2 { font-size: 30px; }
  .main-content { padding: 12px; border-radius: 26px; }
}
@media (max-width: 520px) { nav { grid-template-columns: 1fr; } .app-shell { padding: 8px; } }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display:block; position:absolute; top:0; left:0; width:100%; }
  .document { width: 100%; box-shadow:none; }
}
/* Professional SaaS polish + logo support */
.top-subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.brand-logo-img { width: 100%; height: 100%; object-fit: contain; border-radius: 18px; background: #fff; padding: 4px; }
.doc-logo-img { object-fit: contain; background: #fff; border: 1px solid #e5e7eb; border-radius: 16px; padding: 6px; }
.doc-logo-img.small { width: 56px; height: 56px; }
.doc-logo-img.medium { width: 64px; height: 64px; }
.doc-logo-img.large { width: 88px; height: 88px; }
.doc-logo.medium { width: 64px; height: 64px; }
.doc-logo.large { width: 88px; height: 88px; font-size: 42px; }
.brand-preview { display:flex; gap:16px; align-items:center; padding:16px; border:1px solid rgba(16,47,107,.10); background:rgba(255,255,255,.55); border-radius:22px; margin-bottom:16px; }
.brand-preview b { display:block; font-size:18px; color:var(--primary-dark); }
.brand-preview span { display:block; margin-top:5px; color:var(--muted); font-size:13px; line-height:1.5; }
.sidebar { transform: none; }
.card:hover { transform: translateY(-3px); }
.nav-btn.active { transform: none; }
.nav-btn:hover { transform: translateX(3px); }
.logo { overflow:hidden; }
@media print { .doc-logo-img { print-color-adjust: exact; -webkit-print-color-adjust: exact; } }
.invoice-item-row { display:grid; grid-template-columns: 1.5fr .55fr .8fr auto; gap:10px; align-items:end; padding:12px; border:1px solid rgba(16,47,107,.10); background:rgba(255,255,255,.55); border-radius:18px; margin-bottom:10px; }
.mini-progress { width:120px; height:7px; margin-top:8px; background:rgba(16,47,107,.10); border-radius:99px; overflow:hidden; }
.mini-progress span { display:block; height:100%; background:linear-gradient(90deg, var(--accent), var(--primary-2)); border-radius:99px; }
.small-total { font-size:15px; color:#374151; font-weight:700; }
@media (max-width: 720px){ .invoice-item-row { grid-template-columns:1fr; } }

/* Security/login upgrade */
body.locked .app-shell { filter: blur(8px); pointer-events: none; user-select: none; }
.login-screen { position: fixed; inset: 0; z-index: 999; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 20%, rgba(244,182,63,.35), transparent 30%), linear-gradient(135deg, rgba(6,25,54,.92), rgba(16,47,107,.96)); }
.login-card { width: min(460px, 100%); background: rgba(255,255,255,.92); border: 1px solid rgba(255,255,255,.65); border-radius: 32px; padding: 30px; box-shadow: 0 35px 90px rgba(0,0,0,.35); }
.login-card h1 { margin: 6px 0 6px; color: var(--primary-dark); letter-spacing: -.04em; }
.login-logo { width: 64px; height: 64px; border-radius: 22px; display:flex; align-items:center; justify-content:center; background: linear-gradient(145deg, #fff0b5, var(--accent)); color: var(--primary-dark); font-size: 34px; font-weight: 950; box-shadow: 0 12px 0 rgba(103,69,0,.18), 0 22px 45px rgba(244,182,63,.28); }
.login-help { color: var(--muted); font-size: 13px; line-height: 1.5; }
.session-pill { display:inline-flex; align-items:center; padding: 12px 14px; border-radius: 999px; background: rgba(16,47,107,.08); color: var(--primary-dark); font-weight: 900; border: 1px solid rgba(16,47,107,.10); }
.secure-strip { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:16px; padding:16px; border-radius:22px; background:rgba(255,255,255,.78); border:1px solid rgba(255,255,255,.65); box-shadow:0 14px 30px rgba(9,39,90,.10); }
.secure-strip b { display:block; color:var(--primary-dark); }
.secure-strip span { display:block; color:var(--muted); font-size:13px; margin-top:4px; }
.money-lock { letter-spacing: .02em; }
@media (max-width: 720px){ .secure-strip { flex-direction:column; align-items:flex-start; } .session-pill { width:100%; justify-content:center; } }


/* FIX: Keep Settings accessible even on smaller laptop screens */
.sidebar {
  overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar nav {
  padding-bottom: 24px;
}
#quick-settings {
  display: inline-flex;
}
@media (max-height: 760px) {
  .sidebar {
    height: calc(100vh - 20px);
    top: 10px;
    padding: 18px 14px;
  }
  nav { gap: 7px; }
  .nav-btn { padding: 10px 12px; border-radius: 14px; }
}


/* Month-end closing */
.month-stats { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
.soft-line { border: 0; border-top: 1px solid rgba(16,47,107,.12); margin: 18px 0; }
@media (max-width: 720px){ .month-stats { grid-template-columns:1fr; } }
