:root {
  --navy: #1e2b35;
  --dark: #252827;
  --accent: #b8965a;
  --accent-light: #f5efe6;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --white: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.08);
}

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

html, body {
  height: 100%;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── LOGIN ── */
.screen { min-height: 100vh; }

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #2d3f4e 100%);
}

.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  width: 56px;
  height: auto;
  margin-bottom: 20px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.login-card .field { text-align: left; margin-bottom: 16px; }

/* ── APP LAYOUT ── */
#app-screen {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo-img { width: 28px; height: auto; filter: brightness(0) invert(1); }
.sidebar-logo-text { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.9); line-height: 1.2; }

.nav-links {
  list-style: none;
  padding: 16px 10px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.9); }
.nav-link.active { background: rgba(255,255,255,.12); color: #fff; }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 10px 20px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.55);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.logout-btn svg { width: 16px; height: 16px; }
.logout-btn:hover { background: rgba(255,255,255,.12); color: rgba(255,255,255,.8); }

/* ── MAIN CONTENT ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--navy);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── TOOLBAR ── */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  max-width: 320px;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: var(--white);
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }

.filter-select {
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: var(--white);
  outline: none;
  cursor: pointer;
}

/* ── TABLE ── */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead th {
  background: var(--dark);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 12px 16px;
  text-align: left;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #fafafa; }

.data-table tbody td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--text);
  vertical-align: middle;
}

.data-table .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── STATUS BADGES ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-draft { background: #f3f4f6; color: #6b7280; }
.badge-sent  { background: #dbeafe; color: #1d4ed8; }
.badge-paid  { background: #d1fae5; color: #065f46; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { opacity: .88; }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-secondary:hover { opacity: .88; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.btn-icon { padding: 6px 8px; background: transparent; color: var(--text-muted); border-radius: 6px; }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon svg { width: 16px; height: 16px; }

/* ── FORMS ── */
.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .15s;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

/* ── MODAL ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,20,30,.45);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  background: var(--white);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease;
}

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

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.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(--white);
  z-index: 1;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.modal-close {
  width: 30px; height: 30px;
  border: none; background: transparent;
  font-size: 22px; color: var(--text-muted);
  cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 20px 24px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--white);
}

/* ── ITEMS EDITOR ── */
.items-editor {
  margin: 20px 0 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.items-header {
  display: grid;
  grid-template-columns: 1fr 80px 110px 100px 36px;
  background: var(--dark);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 14px;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 80px 110px 100px 36px;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.item-row:last-child { border-bottom: none; }

.item-row input {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
.item-row input:focus { border-color: var(--accent); }
.item-row input.text-right { text-align: right; }

.item-total { font-size: 13px; font-weight: 600; text-align: right; color: var(--text); }

.remove-item {
  width: 28px; height: 28px;
  background: none; border: none;
  color: #dc2626; cursor: pointer;
  border-radius: 5px; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.remove-item:hover { background: #fee2e2; }

#add-item-btn {
  width: 100%;
  border-top: 1px solid var(--border);
  border-radius: 0;
  justify-content: flex-start;
  padding: 10px 14px;
  font-size: 13px;
}

.invoice-total-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  background: var(--dark);
  color: #fff;
  padding: 12px 14px;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 16px;
  font-weight: 700;
}

/* ── CLIENT INLINE ── */
.client-inline {
  margin-top: 8px;
  padding: 14px;
  background: var(--accent-light);
  border-radius: 8px;
  border: 1.5px solid #e8d8bc;
}

/* ── EMAIL ROWS ── */
.email-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.email-row input { flex: 1; }

/* ── SETTINGS ── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.settings-section {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.settings-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent);
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--dark);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: toastIn .2s ease;
}
.toast.success { border-left: 4px solid #34d399; }
.toast.error   { border-left: 4px solid #f87171; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── ERROR MSG ── */
.error-msg {
  background: #fee2e2;
  color: #dc2626;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; opacity: .35; display: block; }
.empty-state p { font-size: 14px; }

/* ── TAX LIMITS ── */
.limits-rates-box {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 28px;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.limits-rate-item { display: flex; flex-direction: column; gap: 2px; }
.limits-rate-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.limits-rate-value { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.limits-rate-source { font-size: 13px; }
.limits-rate-divider { width: 1px; height: 36px; background: var(--border); margin: 0 20px; }

.limits-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.limit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.limit-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.limit-card-title { font-size: 15px; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; }
.limit-card-subtitle { font-size: 12px; color: var(--text-muted); }

.limit-badge {
  font-size: 12px; font-weight: 700; padding: 4px 12px;
  border-radius: 20px; white-space: nowrap;
}
.limit-badge.ok       { background: #d1fae5; color: #065f46; }
.limit-badge.warning  { background: #fef3c7; color: #92400e; }
.limit-badge.danger   { background: #fee2e2; color: #991b1b; }
.limit-badge.exceeded { background: #7f1d1d; color: #fef2f2; }

.limit-progress-track {
  height: 10px; background: var(--border); border-radius: 999px;
  overflow: hidden; margin-bottom: 20px;
}
.limit-progress-bar {
  height: 100%; border-radius: 999px;
  transition: width .6s ease, background-color .3s;
  background: #22c55e;
}
.limit-progress-bar.warning  { background: #f59e0b; }
.limit-progress-bar.danger   { background: #ef4444; }
.limit-progress-bar.exceeded { background: #7f1d1d; }

.limit-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.limit-stat { display: flex; flex-direction: column; gap: 3px; }
.limit-stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.limit-stat-value { font-size: 14px; font-weight: 700; color: var(--text-primary); }

.limit-breakdown { font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-wrap: wrap; gap: 12px; }
.limit-breakdown-item { display: flex; gap: 5px; }
.limit-breakdown-item strong { color: var(--text-secondary); }
.limit-vat-note { font-size: 11px; color: var(--text-muted); margin-top: 10px; font-style: italic; }

/* ── CHECKBOX FIELD ── */
.field-checkbox { padding-top: 4px; }
.checkbox-label { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.checkbox-label input[type="checkbox"] { margin-top: 2px; width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {

  /* === GLOBAL OVERFLOW FIX === */
  /* Only on html — applying to body breaks iOS fixed positioning */
  html { overflow-x: hidden; }
  body { overflow-x: hidden; max-width: 100vw; }

  /* === LAYOUT === */
  #app-screen { flex-direction: column; overflow-x: hidden; }

  .main-content {
    padding: 16px 14px 76px;
    order: 1;
    overflow-x: hidden;
    min-width: 0;
    width: 100%;
  }

  /* === BOTTOM NAV === */
  .sidebar {
    order: 2;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    z-index: 200;
    padding: 0;
    border-top: 1px solid rgba(255,255,255,.1);
    overflow: visible;
  }

  .sidebar-logo { display: none; }

  .nav-links {
    display: flex;
    flex-direction: row;
    padding: 0;
    flex: 1;
    align-items: stretch;
  }

  .nav-links li { flex: 1; display: flex; }

  .nav-link {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 6px 2px;
    border-radius: 0;
    font-size: 9px;
    margin: 0;
    justify-content: center;
    align-items: center;
    text-align: center;
    line-height: 1.2;
  }

  .nav-link svg { width: 22px; height: 22px; }

  .logout-btn {
    flex-direction: column;
    gap: 3px;
    margin: 0;
    padding: 6px 10px;
    border-radius: 0;
    font-size: 9px;
    justify-content: center;
    align-items: center;
    min-width: 52px;
  }

  .logout-btn svg { width: 22px; height: 22px; }

  /* === PAGE HEADER === */
  .page-header {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    margin-bottom: 16px;
  }

  .page-title { font-size: 20px; }

  .page-header > .btn,
  .page-header > button { width: 100%; justify-content: center; }

  /* === TOOLBAR === */
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .search-input { max-width: 100%; flex: 1 1 100%; }
  .filter-select { flex: 1; }

  /* === TABLE → CARDS === */
  .table-wrap {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }

  .data-table { display: block; }
  .data-table thead { display: none; }
  .data-table tbody { display: block; }

  .data-table tbody tr {
    display: block;
    background: var(--white);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
    border-bottom: none;
    cursor: pointer;
  }

  .data-table tbody td {
    display: block;
    padding: 2px 0;
    font-size: 13px;
    border: none;
  }

  /* Invoice cards */
  .invoice-row td:nth-child(1) { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
  .invoice-row td:nth-child(2) { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
  .invoice-row td:nth-child(3) { font-size: 12px; color: var(--text-muted); }
  .invoice-row td:nth-child(4) { display: none; }
  .invoice-row td:nth-child(5) { font-size: 16px; font-weight: 700; color: var(--navy); margin-top: 4px; }
  .invoice-row td:nth-child(6) { margin-top: 4px; }

  /* Prevent table overflow */
  .table-wrap { max-width: 100%; overflow-x: hidden; }
  .data-table { max-width: 100%; }
  .data-table tbody tr { max-width: 100%; box-sizing: border-box; }

  .row-actions { margin-top: 12px !important; }
  .actions { justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  .actions .btn { font-size: 11.5px; padding: 6px 10px; }

  /* Client cards */
  .client-row td:nth-child(1) { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
  .client-row td:nth-child(2) { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100vw - 60px); }
  .client-row td:nth-child(3) { font-size: 12px; color: var(--text-muted); }
  .client-row td:nth-child(4) { display: none; }

  /* === MODALS — slide up from bottom === */
  .modal { align-items: flex-end; padding: 0; }

  .modal-dialog {
    max-width: 100vw;
    width: 100vw;
    margin: 0;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    animation: modalSlideUp .22s ease;
  }

  @keyframes modalSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  .modal-footer { gap: 8px; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* === INVOICE FORM ITEMS === */
  .form-grid-2 { grid-template-columns: 1fr; gap: 0; }

  input[type="date"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
  }

  .items-editor { overflow-x: hidden; }
  .items-header { display: none; }

  .item-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 8px;
    width: 100%;
    box-sizing: border-box;
  }

  .item-row .item-desc { flex: 1 1 100%; }
  .item-row .item-qty  { flex: 1; min-width: 60px; }
  .item-row .item-price { flex: 2; min-width: 80px; }
  .item-row .item-total { flex: 1; min-width: 60px; font-size: 13px; font-weight: 600; align-self: center; }
  .item-row .remove-item { align-self: center; }

  /* === SETTINGS === */
  .settings-grid { grid-template-columns: 1fr; }

  /* === TAX LIMITS === */
  .limits-cards { grid-template-columns: 1fr; }
  .limits-rates-box { flex-direction: column; gap: 12px; padding: 16px; }
  .limits-rate-divider { display: none; }
  .limits-rates-box { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .limit-stats { grid-template-columns: 1fr 1fr; }
  .limit-card { padding: 18px 16px; }
  .limit-card-header { flex-direction: column; gap: 8px; align-items: flex-start; }

  /* === LOGIN === */
  .login-card { margin: 20px 16px; padding: 32px 24px; }
}
