* {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
}

html, body {
  margin: 0;
  background: #f2f5f9;
  color: #1e2630;
  min-height: 100%;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

[hidden] { display: none !important; }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(65, 105, 225, 0.22), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(21, 59, 112, 0.28), transparent 40%),
    linear-gradient(160deg, #0f2f59 0%, #153b70 45%, #1f6ed4 100%);
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 1.4rem 1.3rem 1.2rem;
  box-shadow: 0 18px 40px rgba(8, 24, 48, 0.28);
}
.login-card h1 {
  margin: 0 0 0.35rem;
  color: #153b70;
}
.login-error {
  color: #b6303c;
  font-weight: 700;
  margin: 0;
}
.logout-link {
  margin-top: 0.4rem;
  background: #f8e9eb !important;
  color: #971823 !important;
  border-color: #efc4c9 !important;
}
.factuur-preview {
  margin-top: 1rem;
  padding-top: 0.4rem;
}

.app-shell[hidden] { display: none !important; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  padding-top: calc(0.85rem + env(safe-area-inset-top));
  background: #153b70;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  flex: 1;
}
.install-pill button {
  background: #4169E1;
  color: #fff;
  border: none;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.menu-toggle, .menu-close {
  width: auto;
  padding: 0.45rem 0.7rem;
  background: #0f2f59;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.menu-toggle:hover, .menu-close:hover { background: #0a2444; }

/* Side menu */
.side-menu {
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100%;
  background: #fff;
  box-shadow: 4px 0 16px rgba(0,0,0,0.2);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 40;
  padding: 1rem;
  padding-top: calc(1rem + env(safe-area-inset-top));
}
.side-menu.open { transform: translateX(0); }

.side-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.side-menu-header h2 { margin: 0; }

.menu-nav { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.menu-link {
  text-align: left;
  background: #f3f6fb;
  color: #1e2630;
  border: 1px solid #e2e8f1;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.menu-link:hover, .menu-link.active { background: #153b70; color: #fff; border-color: #153b70; }

.menu-language {
  display: grid;
  gap: 0.45rem;
  border-top: 1px solid #e2e8f1;
  padding-top: 1rem;
}

.menu-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}
.menu-overlay.open { opacity: 1; pointer-events: auto; }

/* Layout */
.layout {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}
.single-column { max-width: 880px; margin: 0 auto; }

.page { display: none; gap: 1rem; }
.page.active { display: grid; }

.card {
  background: #fff;
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
}

h2 { margin-top: 0; font-size: 1.15rem; }
h3 {
  margin-top: 1.2rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: #34465c;
  border-bottom: 1px solid #e6eaf0;
  padding-bottom: 0.35rem;
}

.meta {
  margin: 0.25rem 0 0.6rem 0;
  color: #43556c;
  font-size: 0.9rem;
}

/* Forms */
.grid-form { display: grid; gap: 0.55rem; }

.form-grid {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 0.6rem;
}
.form-grid.two-cols {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label { display: grid; gap: 0.25rem; font-weight: 600; color: #34465c; font-size: 0.92rem; }
label span { font-weight: 600; }
label.full { grid-column: 1 / -1; }

input, textarea, select {
  width: 100%;
  padding: 0.65rem 0.7rem;
  border: 1px solid #ced4dd;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  font-weight: 400;
  color: #1e2630;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #1f6ed4;
  box-shadow: 0 0 0 2px rgba(31,110,212,0.18);
}
textarea { min-height: 110px; resize: vertical; font-family: inherit; }

button {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: none;
  border-radius: 8px;
  background: #1f6ed4;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
}
button:hover { background: #155bb6; }
button.secondary { background: #687788; }
button.secondary:hover { background: #576476; }
button.danger { background: #b6303c; }
button.danger:hover { background: #971823; }

.action-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.action-row button { width: auto; flex: 1 1 200px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  color: #34465c;
  margin: 0.6rem 0;
}
.checkbox-row input { width: auto; }

/* Payment terms */
.terms { display: grid; gap: 0.5rem; margin-bottom: 0.6rem; }
.term-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 0.5rem;
  align-items: center;
}
.term-row.with-amount {
  grid-template-columns: 80px 110px 1fr auto;
}
.term-row .term-percent { text-align: right; }
.term-row .term-amount {
  text-align: right;
  font-weight: 700;
  color: #1f6ed4;
  font-variant-numeric: tabular-nums;
  padding: 0.4rem 0.5rem;
  background: #eef3fb;
  border: 1px solid #d6e1f0;
  border-radius: 8px;
  white-space: nowrap;
}
.term-row .term-remove {
  width: auto;
  padding: 0.45rem 0.7rem;
  background: #b6303c;
  color: #fff;
}
.term-row .term-remove:hover { background: #971823; }

/* List */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.list-item {
  border: 1px solid #dde4ee;
  border-radius: 10px;
  padding: 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  background: #fcfdff;
}
.list-item .meta { font-size: 0.88rem; }
.list-item.clickable { cursor: pointer; }
.list-item.active {
  border-color: #1f6ed4;
  box-shadow: 0 0 0 2px rgba(31,110,212,0.18);
}
.row-actions { display: flex; gap: 0.4rem; }
.row-actions button {
  width: auto;
  padding: 0.45rem 0.7rem;
  font-size: 0.88rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 200%);
  background: #153b70;
  color: #fff;
  padding: 0.7rem 1.2rem;
  border-radius: 24px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  transition: transform 0.3s ease;
  z-index: 100;
  font-weight: 600;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: #b6303c; }

/* Mobile */
@media (max-width: 720px) {
  .topbar { padding: 0.7rem 0.85rem; padding-top: calc(0.7rem + env(safe-area-inset-top)); }
  .topbar h1 { font-size: 1.05rem; }
  .side-menu { width: 100%; }
  .form-grid.two-cols { grid-template-columns: 1fr; }
  .term-row { grid-template-columns: 70px 1fr auto; }
  .term-row.with-amount { grid-template-columns: 65px 100px 1fr auto; }
  .term-row .term-amount { padding: 0.35rem 0.4rem; font-size: 0.9rem; }
  .action-row button { flex: 1 1 100%; }
}
