*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-main: #111113;
  --bg-card: #1c1c1e;
  --bg-sidebar: #1c1c1e;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --green: #22c55e;
  --green-dark: #16a34a;
  --red: #ef4444;
  --blue: #3b82f6;
  --border: #27272a;
  --input-bg: #27272a;
  --input-border: #3f3f46;
  --radius: 6px;
  --radius-card: 8px;
  --sidebar-width: 220px;
  --topbar-height: 60px;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-main);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── PIN screen ── */
.pin-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-main);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.pin-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 16px;
}

.pin-logo {
  width: 72px;
  height: auto;
  margin-bottom: 4px;
}

.pin-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.pin-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.pin-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 20px;
  letter-spacing: 4px;
  text-align: center;
}

.pin-input:focus { outline: none; border-color: var(--green); }

.pin-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  margin-top: 4px;
}

.pin-error {
  font-size: 13px;
  color: var(--red);
  min-height: 18px;
}

/* ── Shared / customer view mode ── */
body.shared-mode .sidebar,
body.shared-mode .sidebar-overlay,
body.shared-mode .topbar { display: none !important; }
body.shared-mode .main { overflow-y: auto; }
body.shared-mode #pageContainer { padding: 0; background: #f0f0f0; min-height: 100vh; }

.shared-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 0 60px;
}

.shared-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #1c1c1e;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.shared-topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: #f4f4f5;
}

.shared-brand-logo {
  height: 32px;
  width: auto;
}

.shared-loading,
.shared-notfound,
.shared-error {
  text-align: center;
  padding: 80px 20px;
  font-size: 16px;
  color: var(--text-secondary);
}
.shared-error { color: var(--red); }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  padding: 20px 16px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-box {
  width: 160px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo-img {
  width: 100%;
  height: auto;
  display: block;
}

.sidebar-logo-initials {
  font-size: 28px;
  font-weight: 800;
  color: #1c1c1e;
  letter-spacing: 2px;
}

.sidebar-brand-text {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 8px 8px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: color 0.15s, background 0.15s;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.nav-link.active {
  color: var(--green);
  border-left-color: var(--green);
  background: rgba(34,197,94,0.08);
}

.nav-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  border-top: 1px solid var(--border);
}

.sidebar-footer span {
  cursor: pointer;
}

.sidebar-footer span:hover {
  color: var(--text-primary);
}

/* ── Main layout ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-main);
}

/* ── Top bar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-main);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  gap: 16px;
}

.topbar-left {
  flex-shrink: 0;
}

.topbar-left h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 360px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 12px 7px 34px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.search-input::placeholder { color: var(--text-secondary); }
.search-input:focus { border-color: var(--green); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}

.topbar-icon-btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
}

.notif-bell-btn { position: relative; }

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  pointer-events: none;
}

.notif-dropdown {
  position: fixed;
  z-index: 1000;
  width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  overflow: hidden;
}

.notif-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.notif-mark-read {
  font-size: 12px;
  color: var(--green);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.notif-list {
  max-height: 360px;
  overflow-y: auto;
}

.notif-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(34,197,94,0.06);
}

.notif-item:last-child { border-bottom: none; }

.notif-item.notif-read { background: none; }

.notif-item-msg {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.notif-item-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.topbar-user:hover {
  background: rgba(255,255,255,0.06);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--green-dark);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.user-chevron {
  color: var(--text-secondary);
}

/* ── Page container ── */
.page-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.page-content {
  max-width: 1100px;
}

.page-content.full-height {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: none;
  min-height: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-green {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-green:hover { background: var(--green-dark); border-color: var(--green-dark); }

.btn-fab {
  background: transparent;
  border-color: transparent;
  color: var(--green);
  font-size: 34px;
  line-height: 1;
  padding: 0 4px;
  margin-left: 12px;
}
.btn-fab:hover { background: transparent; border-color: transparent; color: var(--green-dark); }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--input-border);
}
.btn-outline:hover { background: rgba(255,255,255,0.05); }

.btn-dark {
  background: var(--input-bg);
  color: var(--text-primary);
  border-color: var(--input-border);
}
.btn-dark:hover { background: #323236; }

.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-secondary);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-icon:hover { background: rgba(255,255,255,0.07); color: var(--text-primary); }

/* keep old names working from modal forms */
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border); }
.btn-secondary:hover { background: #323236; }
.btn-disabled, button:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: var(--green-dark); }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--green); border-bottom-color: var(--green); }

/* ── Month group ── */
.month-group {
  margin-bottom: 28px;
}

.month-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.month-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.month-total {
  font-size: 12px;
  color: var(--text-secondary);
}

.month-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin-bottom: 0;
}

/* ── Invoice / Estimate rows ── */
.row-list {
  display: flex;
  flex-direction: column;
}

.invoice-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.invoice-row:first-child { border-radius: var(--radius-card) var(--radius-card) 0 0; }
.invoice-row:last-child { border-radius: 0 0 var(--radius-card) var(--radius-card); border-bottom: none; }
.invoice-row:only-child { border-radius: var(--radius-card); border-bottom: none; }
.invoice-row:hover { background: #222226; }

.row-main {
  flex: 2;
  min-width: 0;
}

.row-client {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
}

.row-client:hover { color: var(--green); }

.row-number {
  font-weight: 400;
  color: var(--text-secondary);
}

.row-date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.row-status {
  flex-shrink: 0;
  width: 90px;
}

.row-address {
  flex: 1.5;
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 0;
  overflow: hidden;
}

.row-address-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-draft {
  background: transparent;
  border: 1px solid var(--text-secondary);
  color: var(--text-secondary);
}

.badge-sent {
  background: var(--blue);
  color: #fff;
}

.badge-paid, .badge-accepted {
  background: var(--green-dark);
  color: #fff;
}

.badge-partial {
  background: #d97706;
  color: #fff;
}

.badge-overdue, .badge-declined {
  background: var(--red);
  color: #fff;
}

.badge-issued {
  background: var(--blue);
  color: #fff;
}

.badge-approved {
  background: var(--green-dark);
  color: #fff;
}

.badge-expired {
  background: #ea580c;
  color: #fff;
}

.badge-signed {
  background: #7c3aed;
  color: #fff;
}

/* keep old badge names for modal etc */
.badge-gray { background: transparent; border: 1px solid var(--text-secondary); color: var(--text-secondary); }
.badge-blue { background: var(--blue); color: #fff; }
.badge-green { background: var(--green-dark); color: #fff; }
.badge-red { background: var(--red); color: #fff; }
.badge-yellow { background: #ca8a04; color: #fff; }

/* ── Dashboard stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card.skeleton {
  height: 100px;
  background: linear-gradient(90deg, var(--bg-card) 25%, #222224 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-secondary); }

/* ── Clients page ── */
/* ── Clients split-panel layout ── */
.clients-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.clients-list-panel {
  width: 380px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-right: 16px;
}

.clients-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.clients-list-header-left { display: flex; align-items: center; gap: 10px; }

.toggle-wrap {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle-wrap input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #3f3f46;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-wrap input:checked + .toggle-slider { background: var(--green); }
.toggle-wrap input:checked + .toggle-slider::before { transform: translateX(16px); }

.toggle-label { font-size: 13px; color: var(--text-secondary); }

.btn-icon-sm {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.btn-icon-sm:hover { background: var(--input-bg); color: var(--text-primary); }

.clients-list-body {
  flex: 1;
  overflow-y: auto;
}

.alpha-group { }

.alpha-header {
  padding: 8px 16px 4px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.client-list-item {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.client-list-item:hover { background: rgba(255,255,255,0.04); }
.client-list-item.active { background: rgba(34,197,94,0.08); color: var(--green); }

.clients-empty { padding: 24px 16px; color: var(--text-secondary); font-size: 13px; }

/* Right form panel */
.clients-form-panel {
  flex: 1;
  background: var(--bg-card);
  border-radius: 8px;
  overflow-y: auto;
  min-width: 0;
}

.client-form-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  color: var(--text-secondary);
  font-size: 14px;
}
.client-form-empty strong { color: var(--text-primary); }

.client-form-inner { padding: 28px 32px; }

.client-form-section { margin-bottom: 28px; }

.client-form-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.client-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.inline-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-main);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}
.inline-input:focus { outline: none; border-color: var(--green); }
.inline-input::placeholder { color: var(--text-secondary); }

.inline-textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
}

.client-form-actions {
  display: flex;
  align-items: center;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

/* ── Client view (read-only) ── */
.clients-mob-nav {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}

.client-view-inner { padding: 24px 28px; }

.client-view-section { margin-bottom: 20px; }

.client-view-name {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.client-view-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.client-view-detail {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.6;
}

.client-view-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.client-view-edit-row {
  margin-top: 12px;
}

/* ── Document editor (full-page form) ── */
.doc-page {
  background: #f0f0f0;
  min-height: 100%;
  padding: 0;
}

.doc-topbar {
  background: var(--bg-sidebar);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.more-dropdown-wrap {
  position: relative;
}

.more-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  min-width: 190px;
  z-index: 200;
  overflow: hidden;
}

.more-dropdown.open {
  display: block;
}

.more-dropdown-item {
  display: block;
  width: 100%;
  padding: 11px 16px;
  text-align: left;
  background: none;
  border: none;
  font-size: 14px;
  color: #222;
  cursor: pointer;
  white-space: nowrap;
}

.more-dropdown-item:hover {
  background: #f5f5f5;
}

.doc-card {
  background: #fff;
  margin: 16px;
  padding: 40px 48px;
  border-radius: 6px;
  color: #333;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.doc-card input, .doc-card textarea, .doc-card select {
  background: #fff;
  border: 1px solid #ccc;
  color: #333;
  border-radius: 4px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.doc-card input:focus, .doc-card textarea:focus, .doc-card select:focus {
  border-color: #22c55e;
}

.doc-card input[readonly] {
  background: #f5f5f5;
  color: #666;
  cursor: default;
}

/* Header row */
.doc-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 32px;
  margin-bottom: 24px;
}

.doc-header-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.doc-logo {
  max-width: 180px;
  height: auto;
  display: block;
}

.doc-license {
  font-size: 12px;
  color: #555;
  font-weight: 500;
}

.doc-company-addr {
  font-size: 12px;
  color: #555;
  line-height: 1.6;
  margin-top: 4px;
}

.doc-header-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
}

.doc-client-section {
  margin-bottom: 4px;
}

.doc-client-select {
  font-size: 13px;
  font-weight: 600;
  color: #16a34a !important;
  border-color: #16a34a !important;
  background: #fff;
  cursor: pointer;
  width: 100%;
}

.doc-client-display {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}

.doc-client-name {
  font-size: 14px;
  font-weight: 700;
  color: #222;
}

.doc-client-info {
  font-size: 12px;
  color: #555;
  line-height: 1.5;
}

.doc-change-client-btn {
  margin-top: 6px;
  background: none;
  border: none;
  color: #16a34a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
  text-align: left;
}

.doc-meta-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-meta-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 8px;
}

.doc-meta-row .badge { justify-self: start; }

.doc-meta-row label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Divider */
.doc-divider {
  border: none;
  border-top: 1px solid #ddd;
  margin: 0 0 20px;
}

/* Line items table */
/* ── Line items — Joist-style grid table ── */

/* Column grid: same for header, form rows, and view rows */
.doc-line-header,
.doc-line-row,
.doc-line-row-view {
  display: grid;
  grid-template-columns: 1fr 130px 110px 100px 80px 120px;
  align-items: stretch;
}

/* Header */
.doc-line-header {
  padding: 0 0 8px 44px; /* 36px delete btn + 8px gap to align with card */
  border-bottom: 2px solid #333;
  margin-bottom: 10px;
}
/* View header has no delete button offset */
.doc-line-header.no-offset {
  padding-left: 0;
}

.doc-lh-desc {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: #444; padding: 4px 0;
}
.doc-lh-rate, .doc-lh-markup, .doc-lh-qty, .doc-lh-tax, .doc-lh-total, .doc-lh-del {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: #444;
  text-align: center; padding: 4px 8px;
}
.doc-lh-total { text-align: right; }
.doc-lh-del { width: 36px; }

/* Outer wrapper: delete button left + card right */
.doc-line-outer {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.doc-remove-line {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-top: 10px;
  background: none;
  border: 1px solid #ddd;
  border-radius: 50%;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all 0.15s;
}
.doc-remove-line:hover { color: #ef4444; border-color: #ef4444; background: #fee2e2; }

/* The card itself */
.doc-line-item {
  flex: 1;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

/* Top row inside card */
.doc-line-row {
  align-items: center;
  min-height: 46px;
}

.doc-line-desc-cell {
  padding: 8px 12px;
  border-right: 1px solid #e8e8e8;
}

.doc-line-title-input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  font-family: inherit;
  outline: none;
  resize: none;
  overflow: hidden;
  display: block;
  line-height: 1.4;
  padding: 0;
  min-height: 1.4em;
}
.doc-line-title-input::placeholder { font-weight: 400; color: #bbb; }

/* Number input cells — each has a left border (cell divider) */
.doc-line-rate,
.doc-line-markup,
.doc-line-qty {
  width: 100%;
  height: 100%;
  border: none;
  border-right: 1px solid #e8e8e8;
  padding: 8px 12px;
  font-size: 14px;
  color: #333;
  background: transparent;
  font-family: inherit;
  outline: none;
  text-align: center;
  min-width: 0;
}
.doc-line-rate:focus,
.doc-line-markup:focus,
.doc-line-qty:focus { background: #f0fdf4; }
.doc-line-markup::placeholder,
.doc-line-qty::placeholder { color: #bbb; }

.doc-line-tax {
  width: 100%;
  height: 100%;
  border: none;
  border-right: 1px solid #e8e8e8;
  padding: 8px 12px;
  font-size: 14px;
  color: #333;
  background: transparent;
  font-family: inherit;
  outline: none;
  text-align: center;
  min-width: 0;
}
.doc-line-tax:focus { background: #f0fdf4; }
.doc-line-tax::placeholder { color: #bbb; }

.doc-line-amount-cell {
  text-align: right;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.doc-line-amount { font-size: 14px; font-weight: 600; color: #333; }

/* Details textarea inside card */
.doc-line-details-wrap {
  border-top: 1px solid #e8e8e8;
}
.doc-line-details {
  width: 100%;
  border: none;
  padding: 10px 12px;
  font-size: 13px;
  color: #444;
  background: #fafafa;
  resize: none;
  overflow: hidden;
  min-height: 44px;
  font-family: inherit;
  outline: none;
  display: block;
  line-height: 1.7;
}
.doc-line-details:focus { background: #fff; }

/* View-mode line items */
.doc-line-item-view {
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  margin-bottom: 10px;
  overflow: hidden;
  background: #fff;
}

.doc-line-row-view {
  align-items: center;
  min-height: 46px;
}

.doc-line-row-view .doc-line-desc-cell {
  padding: 10px 12px;
  border-right: 1px solid #e8e8e8;
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.dlv-rate, .dlv-markup, .dlv-qty, .dlv-tax {
  text-align: center; font-size: 13px; color: #555;
  padding: 10px 8px; border-right: 1px solid #e8e8e8;
}
.dlv-total { text-align: right; font-size: 14px; font-weight: 600; color: #333; padding: 10px 12px; }

.doc-line-details-view {
  border-top: 1px solid #e8e8e8;
  padding: 10px 12px;
  font-size: 13px;
  color: #444;
  white-space: pre-line;
  background: #fafafa;
  line-height: 1.7;
}

.doc-add-line-btn {
  display: inline-block;
  margin: 8px 0 24px;
  background: none;
  border: 1px solid #16a34a;
  color: #16a34a;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.doc-add-line-btn:hover { background: #f0fdf4; }

/* Totals */
.doc-totals {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 32px;
}

.doc-payments-in-view {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.doc-pay-view-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.doc-pay-view-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #444;
}

.doc-pay-view-date {
  color: var(--text-secondary);
  white-space: nowrap;
}

.doc-pay-view-method {
  flex: 1;
  font-weight: 500;
}

.doc-pay-view-amount {
  font-weight: 600;
  white-space: nowrap;
}

.doc-paid-in-full {
  margin-top: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--green-dark);
  border: 2px solid var(--green-dark);
  border-radius: 6px;
  padding: 6px 10px;
}

.doc-totals-inner {
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #555;
  gap: 12px;
}

.doc-totals-grand {
  font-weight: 700;
  font-size: 15px;
  color: #333;
  border-top: 1px solid #ddd;
  padding-top: 8px;
  margin-top: 4px;
}

.doc-tax-rate-input {
  width: 80px !important;
  text-align: right;
}

/* Notes */
.doc-notes-section {
  margin-bottom: 20px;
}

.doc-notes-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  margin-bottom: 6px;
}

.doc-private-hint {
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  color: #aaa;
  letter-spacing: 0;
}

.doc-notes-textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  font-size: 13px;
  color: #333;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 8px 12px;
  font-family: inherit;
  outline: none;
}
.doc-notes-textarea:focus { border-color: #22c55e; }

.doc-contract-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.doc-contract-text {
  font-size: 11px;
  color: #666;
  line-height: 1.6;
  white-space: pre-wrap;
  font-family: inherit;
}

/* ── Document view restructured layout ── */
.doc-view-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.doc-view-logo-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.doc-view-company {
  flex: 1;
  min-width: 0;
}

.doc-view-company-name {
  font-weight: 700;
  font-size: 12px;
  color: #111;
  margin-bottom: 4px;
}

.doc-view-company-detail {
  font-size: 11px;
  color: #555;
  line-height: 1.5;
}

.doc-view-section {
  padding: 14px 0;
}

.doc-view-section-label {
  font-weight: 700;
  font-size: 14px;
  color: #111;
  margin-bottom: 6px;
}

.doc-view-client-name {
  font-size: 14px;
  font-weight: 600;
  color: #222;
  margin-bottom: 2px;
}

.doc-view-client-detail {
  font-size: 13px;
  color: #555;
  line-height: 1.6;
}

.doc-view-meta {
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-view-meta-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 8px;
}

.doc-view-meta-row .badge { justify-self: start; }

.doc-view-meta-label {
  font-size: 12px;
  color: #666;
}

.doc-view-meta-value {
  font-size: 13px;
  color: #222;
  font-weight: 500;
}

.doc-view-line-header {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  color: #333;
  padding: 10px 0 6px;
}

.doc-signature-section {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-top: 48px;
  padding-bottom: 24px;
}

.doc-signature-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: 100%;
  margin-bottom: 20px;
}
.doc-signature-block:last-child { margin-bottom: 0; }

.doc-signature-img {
  width: 50%;
  max-height: 72px;
  object-fit: contain;
  object-position: bottom center;
  margin-bottom: 2px;
}

.doc-signature-line {
  width: 50%;
  border-top: 1px solid #444;
  margin-bottom: 8px;
}

.doc-signature-name {
  width: 50%;
  text-align: center;
  font-size: 11px;
  color: #555;
}

/* ── Settings layout ── */
.settings-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.settings-nav-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.settings-nav-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.settings-nav-btn.active { color: var(--green); background: rgba(34,197,94,0.08); border-left-color: var(--green); }

.settings-content-panel {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 28px 32px;
}

.settings-section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.settings-field {
  margin-bottom: 14px;
}

.settings-field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}

.settings-input {
  width: 100%;
  max-width: 420px;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.settings-input:focus { border-color: var(--green); }

.settings-save-row {
  margin-top: 20px;
}

/* ── Old table styles (kept for modals / line-items) ── */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid var(--border);
}

.table th {
  background: var(--bg-card);
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.03); }
.table td.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty, .loading {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 14px !important;
  font-style: italic;
}

/* ── Empty state (flex list) ── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
}

/* ── Modal ── */
/* ── Send dropdown (appears below SEND button) ── */
.send-dropdown-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1999;
}

.send-dropdown {
  position: fixed;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.22), 0 2px 8px rgba(0,0,0,0.1);
  min-width: 270px;
  z-index: 2000;
  overflow: visible;
  animation: dropIn 0.15s ease;
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.send-dropdown-arrow {
  position: absolute;
  top: -7px;
  width: 14px;
  height: 14px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 2px 0 0 0;
  box-shadow: -2px -2px 4px rgba(0,0,0,0.06);
}

.send-dropdown-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  text-decoration: none;
  color: #111;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
}
.send-dropdown-item:first-of-type { border-radius: 14px 14px 0 0; }
.send-dropdown-item:last-child { border-bottom: none; border-radius: 0 0 14px 14px; }
.send-dropdown-item:active { background: #f5f5f5; }

.send-dropdown-item-dim { opacity: 0.4; cursor: default; }

.send-dropdown-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: #1c1c1e;
  border-radius: 9px;
  color: #fff;
  flex-shrink: 0;
}

.send-dropdown-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: #222;
  text-transform: uppercase;
}

.send-dropdown-sub {
  display: block;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: #999;
  margin-top: 1px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-lg { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 10;
}

.modal-header h2 { font-size: 17px; font-weight: 600; color: var(--text-primary); }

/* ── Forms ── */
.form { padding: 20px 24px 24px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label { font-weight: 500; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-group-inline { flex-direction: row; align-items: center; gap: 10px; margin-bottom: 0; }

.required { color: var(--red); }

.form input, .form select, .form textarea {
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--input-bg);
  transition: border-color .15s;
  font-family: inherit;
}

.form input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  border-color: var(--green);
}

.form input[readonly] { background: #1a1a1c; color: var(--text-secondary); cursor: default; }

.form select option { background: var(--bg-card); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Line items table (inside modal) ── */
.line-items-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.line-items-table th {
  background: var(--bg-main);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}

.line-items-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--border);
}

.line-items-table tr:last-child td { border-bottom: none; }

.line-items-table input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-family: inherit;
}

.line-items-table input:focus { outline: none; border-color: var(--green); }

.line-items-table textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 12px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-family: inherit;
  resize: vertical;
}
.line-items-table textarea:focus { outline: none; border-color: var(--green); }

.line-items-table td.line-amount {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  padding: 6px 10px;
}

/* ── Totals ── */
.totals-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.totals-display { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }

.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-secondary);
}

.totals-total {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  padding-top: 6px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Error ── */
.error-state {
  padding: 40px 24px;
  color: var(--red);
  background: rgba(239,68,68,0.1);
  border-radius: var(--radius-card);
  text-align: center;
  border: 1px solid rgba(239,68,68,0.3);
}

/* ── Contract cards ── */
.contract-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.contract-card:hover { border-color: var(--green); background: rgba(34,197,94,0.04); }

.contract-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 12px;
}

.contract-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.contract-card-preview {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contract-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(34,197,94,0.15);
  color: var(--green);
  white-space: nowrap;
}

/* ── Legacy settings-card (kept for backward compat) ── */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  max-width: 480px;
}

.settings-card h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* ── Hamburger button (hidden on desktop) ── */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin-right: 10px;
  flex-shrink: 0;
}
.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: 0.2s;
}

/* ── Sidebar overlay (mobile only) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s;
}

/* ── Mobile styles ── */
@media (max-width: 640px) {
  body { overflow: auto; height: 100dvh; }

  /* Sidebar slides in as overlay */
  .sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-width) - 2px);
    top: 0;
    bottom: 0;
    z-index: 400;
    transition: left 0.25s ease;
  }
  .sidebar.mobile-open { left: 0; }

  .sidebar-overlay {
    display: block;
    pointer-events: none;
  }
  .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main takes full width */
  .main { width: 100%; }

  /* Topbar */
  .hamburger-btn { display: flex; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-center { display: flex; gap: 6px; }
  .topbar-center .search-wrap,
  .topbar-center #exportBtn { display: none; }
  .topbar-right .user-name,
  .topbar-right .user-chevron,
  .topbar-right .topbar-icon-btn:last-child { display: none; }
  .notif-bell-btn { display: flex !important; }
  .topbar-left h1 { font-size: 15px; }

  /* Page container scrolls */
  .page-container { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* List row actions — wrap on small screens */
  .row-actions { flex-wrap: wrap; }
  .invoice-row { flex-wrap: wrap; gap: 6px; padding: 12px; }
  .row-main { min-width: 0; }
  .row-amount { min-width: unset; }

  /* Doc card — tighter padding */
  .doc-card { margin: 8px; padding: 20px 16px; }

  /* Doc topbar */
  .doc-topbar { padding: 10px 12px; }

  /* Doc header — stack company + client */
  .doc-header-row { flex-direction: column; gap: 16px; }
  .doc-header-right { min-width: unset; width: 100%; }
  .doc-logo { max-width: 130px; }

  /* Line item column header — hide on mobile, labels implied by context */
  .doc-line-header { display: none; }

  /* Line item edit rows — 2-col grid for numbers */
  .doc-line-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
  }
  .doc-line-desc-cell {
    grid-column: 1 / -1;
  }
  .doc-line-amount-cell {
    grid-column: 2;
    justify-content: flex-end;
  }

  /* Line item view rows */
  .doc-line-row-view {
    grid-template-columns: 1fr auto;
  }
  .doc-line-row-view .doc-line-desc-cell { grid-column: 1; }
  .dlv-rate, .dlv-markup, .dlv-qty, .dlv-tax { display: none; }
  .dlv-total { font-weight: 600; }

  /* Totals */
  .doc-totals-inner { min-width: unset; width: auto; }

  /* Settings layout */
  .settings-layout { flex-direction: column; }
  .settings-nav-panel {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
    gap: 4px;
  }
  .settings-nav-btn { padding: 6px 10px; font-size: 11px; }

  /* Clients panel */
  .clients-layout { flex-direction: column; }
  .clients-list-panel { border-right: none; border-bottom: 1px solid var(--border); margin-right: 0; }
  .clients-detail-panel { width: 100%; }

  /* Clients mobile nav + detail mode */
  .clients-mob-nav.active { display: flex !important; }
  .client-desktop-only { display: none !important; }

  .clients-layout.detail-mode .clients-list-panel { display: none; }
  .clients-layout.detail-mode .clients-form-panel {
    width: 100%;
    border-radius: 0;
  }

  /* Modals */
  .modal { margin: 16px; max-width: calc(100vw - 32px) !important; }

  /* Mobile view: hide desktop topbar, show mobile nav */
  .doc-page .doc-topbar { display: none; }
  .doc-mob-topnav,
  .doc-mob-actionbar,
  .doc-mob-statusbar { display: flex !important; }

}


/* ── Mobile document view nav/action bar (hidden on desktop) ── */
.doc-type-banner {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #bbb;
  text-transform: uppercase;
  margin-bottom: 20px;
}

.doc-mob-topnav,
.doc-mob-actionbar,
.doc-mob-statusbar { display: none; }

.doc-mob-topnav {
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.doc-mob-nav-btn {
  background: none;
  border: none;
  font-size: 15px;
  color: #555;
  cursor: pointer;
  padding: 4px 0;
  min-width: 60px;
}
.doc-mob-nav-save {
  color: #16a34a;
  font-weight: 600;
  text-align: right;
}
.doc-mob-nav-title {
  font-size: 15px;
  font-weight: 600;
  color: #111;
}

.doc-mob-back {
  display: flex;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--green);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}

.doc-mob-docnum {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.doc-mob-editbtn {
  background: none;
  border: none;
  color: var(--green);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}

.doc-mob-actionbar {
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  position: relative;
}

.doc-mob-action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  background: none;
  border: none;
  border-right: 1px solid #e5e5e5;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #222;
  cursor: pointer;
}
.doc-mob-action:last-child { border-right: none; }
.doc-mob-action svg { color: #333; }
.doc-mob-action-dim { opacity: 0.35; cursor: not-allowed; }

.doc-mob-more-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  z-index: 50;
  min-width: 180px;
  overflow: hidden;
}
.doc-mob-more-menu.open { display: block; }

.doc-mob-more-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
  color: #222;
  text-align: left;
  cursor: pointer;
}
.doc-mob-more-item:last-child { border-bottom: none; }
.doc-mob-more-item:active { background: #f5f5f5; }
.doc-mob-more-danger { color: #dc2626; }

.doc-mob-statusbar {
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  background: #52525b;
  transition: background 0.2s;
}

.doc-mob-status-sel {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #fff;
  cursor: pointer;
  outline: none;
}

/* ── Desktop/Mobile view segmented control ── */
.doc-view-seg-wrap {
  display: flex;
  justify-content: center;
  padding: 10px 16px;
  background: var(--bg-main);
  border-bottom: 1px solid var(--border);
}

.doc-view-seg {
  display: flex;
  background: var(--input-bg);
  border-radius: 8px;
  padding: 2px;
  width: 100%;
  max-width: 260px;
}

.doc-view-seg-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.doc-view-seg-btn.active {
  background: #fff;
  color: #111;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}

/* ── Payment Modal ── */
.pay-modal {
  max-width: 480px;
  width: 95%;
  border-radius: 12px;
  overflow: hidden;
}
.pay-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.pay-modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.pay-back-btn {
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-primary);
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.pay-summary {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.pay-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-secondary);
}
.pay-due { color: var(--text-primary); }
.pay-progress-track {
  height: 8px;
  background: var(--input-bg);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.pay-progress-bar {
  height: 100%;
  background: #52525b;
  border-radius: 4px;
  transition: width 0.3s;
  min-width: 0;
}
.pay-progress-bar.full { background: var(--green); }
.pay-progress-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 2px 10px;
  background: var(--input-bg);
  border-radius: 4px;
  display: inline-block;
  margin-top: 2px;
}
.pay-list {
  padding: 0 24px;
  max-height: 240px;
  overflow-y: auto;
}
.pay-empty {
  color: var(--text-secondary);
  font-size: 14px;
  padding: 24px 0;
  text-align: center;
}
.pay-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.pay-row:last-child { border-bottom: none; }
.pay-row-info { display: flex; flex-direction: column; gap: 2px; }
.pay-row-method { font-size: 14px; font-weight: 500; }
.pay-row-date { font-size: 12px; color: var(--text-secondary); }
.pay-row-right { display: flex; align-items: center; gap: 12px; }
.pay-row-amount { font-size: 15px; font-weight: 600; }
.pay-row-del {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}
.pay-row-del:hover { color: #ef4444; }
.pay-modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}
/* Form view */
.pay-form { padding: 16px 24px 4px; }
.pay-form-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.pay-amount-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 12px;
}
.pay-amount-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.pay-currency-sym {
  position: absolute;
  left: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  pointer-events: none;
}
.pay-amount-input {
  width: 100%;
  padding: 10px 10px 10px 24px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  background: var(--input-bg);
  color: var(--text-primary);
  box-sizing: border-box;
}
.pay-amount-input:focus { outline: none; border-color: var(--green); }
.pay-mode-btns {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.pay-mode-btn {
  padding: 0 14px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.pay-mode-btn:last-child { border-right: none; }
.pay-mode-btn.active { background: var(--green); color: #fff; }
.pay-date-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text-primary);
  box-sizing: border-box;
  margin-bottom: 16px;
}
.pay-date-input:focus { outline: none; border-color: var(--green); }
.pay-method-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.pay-method-btn {
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.pay-method-btn.active { background: var(--green); border-color: var(--green); color: #fff; }

.pay-check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.pay-check-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}
.pay-check-input {
  width: 140px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text-primary);
}
.pay-check-input:focus { outline: none; border-color: var(--green); }

/* Desktop payments button */
.btn-payments {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Photo upload (form) ── */
.doc-photos-section {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.doc-photos-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.doc-photo-thumb {
  position: relative;
  width: 90px;
  height: 90px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.doc-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.doc-photo-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 1;
}
.doc-photo-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  background: var(--input-bg);
  transition: border-color 0.15s;
}
.doc-photo-upload-label:hover { border-color: var(--green); color: var(--green); }
.doc-photo-uploading { opacity: 0.5; pointer-events: none; }

/* ── Photo view (read-only doc) ── */
.doc-photos-view-section {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.doc-photos-view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.doc-photos-view-grid .doc-photo-thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 4/3;
  overflow: hidden;
  border-radius: 6px;
}
.doc-photos-view-grid .doc-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

/* ── Desktop PDF iframe ── */
.doc-desktop-frame {
  width: 100%;
  border: none;
  background: #e5e5e5;
  height: calc(100vh - 120px);
  min-height: 500px;
}

/* ── Mobile summary view (unused — kept for reference) ── */
.doc-mob-summary {
  display: none;
  flex-direction: column;
  background: var(--bg-main);
  flex: 1;
  overflow-y: auto;
}

.dms-section {
  background: var(--bg-card);
  padding: 16px 20px;
  margin-bottom: 8px;
}

.dms-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.dms-client-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.dms-detail {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.dms-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-primary);
}
.dms-row:last-child { border-bottom: none; }

.dms-row-label { color: var(--text-secondary); }

.dms-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.dms-item:last-child { border-bottom: none; }

.dms-item-desc {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.dms-item-total {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  flex-shrink: 0;
}

.dms-total-row { font-weight: 600; }

.dms-grand-total {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
}

/* ── Print styles ── */
@media print {
  .doc-mob-topnav,
  .doc-mob-actionbar,
  .doc-mob-statusbar,
  .doc-view-seg-wrap,
  .doc-mob-summary,
  .doc-desktop-frame,
  .doc-topbar,
  .topbar,
  .sidebar { display: none !important; }

  /* Remove all overflow and height constraints so full content prints */
  html, body,
  .main,
  .page-container,
  .page-content,
  .doc-page {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    display: block !important;
    flex: none !important;
  }

  .doc-card {
    display: block !important;
    box-shadow: none;
    border: none;
    margin: 0;
    padding: 20px;
  }

  body, .doc-page { background: #fff !important; }

  /* Allow page breaks inside line items and contract text */
  .doc-contract-section,
  .doc-line-item-view { page-break-inside: avoid; }
}

/* ── Sign Modal ─────────────────────────────────────────────────── */
.sign-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: rotate(90deg);
  background: #fff;
  z-index: 3000;
  display: flex;
  align-items: stretch;
}

.sign-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
}

.sign-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #f9f9f9;
  flex-shrink: 0;
}

.sign-cancel {
  background: none;
  border: none;
  font-size: 15px;
  color: #555;
  cursor: pointer;
  padding: 4px 0;
}

.sign-title {
  font-size: 16px;
  font-weight: 600;
  color: #111;
}

.sign-save {
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: #16a34a;
  cursor: pointer;
  padding: 4px 0;
}

.sign-canvas-area {
  flex: 1;
  position: relative;
  background: #fafafa;
  overflow: hidden;
}

.sign-canvas-area canvas {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.sign-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: rgba(0,0,0,0.06);
  letter-spacing: 0.15em;
  pointer-events: none;
  user-select: none;
}

.sign-baseline-wrap {
  padding: 0 24px 8px;
  flex-shrink: 0;
}

.sign-baseline-line {
  border-top: 1.5px solid #333;
  margin-bottom: 4px;
}

.sign-baseline-name {
  font-size: 12px;
  color: #555;
  text-align: center;
}

.sign-bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid #e0e0e0;
  background: #f9f9f9;
  flex-shrink: 0;
  position: relative;
}

.sign-segment {
  display: flex;
  background: #e0e0e0;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.sign-seg {
  background: none;
  border: none;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sign-seg.active {
  background: #fff;
  color: #111;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.sign-bottombar-right {
  display: flex;
  gap: 8px;
}

.sign-bottom-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
}
.sign-bottom-btn:active { background: #f0f0f0; }

/* Options popover */
.sign-options-pop {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  right: 16px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 200px;
  z-index: 10;
  overflow: hidden;
}
.sign-options-pop.visible { display: block; }

.sign-opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
  color: #111;
}
.sign-opt-row:last-child { border-bottom: none; }

/* iOS-style toggle */
.sign-toggle-label { position: relative; display: inline-block; width: 44px; height: 26px; }
.sign-toggle-input { opacity: 0; width: 0; height: 0; position: absolute; }
.sign-toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 13px;
  background: #ccc;
  transition: background 0.2s;
  cursor: pointer;
}
.sign-toggle-track::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.sign-toggle-input:checked + .sign-toggle-track { background: #16a34a; }
.sign-toggle-input:checked + .sign-toggle-track::after { transform: translateX(18px); }

/* Contract viewer */
.sign-contract-view {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.sign-contract-inner {
  background: #fff;
  width: 100%;
  max-height: 75vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sign-contract-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}

.sign-contract-close {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: #16a34a;
  cursor: pointer;
  padding: 4px 0;
  width: 60px;
  text-align: right;
}

.sign-contract-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 13px;
  color: #333;
  line-height: 1.7;
  -webkit-overflow-scrolling: touch;
}
