:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-2: #f7fafc;
  --text: #1b2430;
  --muted: #6d7b8d;
  --line: #dde5ee;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #e8f0ff;
  --danger: #c2410c;
  --danger-soft: #fff1eb;
  --success: #15803d;
  --success-soft: #ebfbef;
  --warning: #a16207;
  --warning-soft: #fff8e6;
  --sidebar: #122033;
  --sidebar-soft: rgba(255,255,255,0.08);
  --shadow: 0 14px 34px rgba(17, 24, 39, 0.08);
  --shadow-soft: 0 8px 18px rgba(17, 24, 39, 0.06);
  --radius: 18px;

  --invoice-text: #2b3643;
  --date-text: #556273;
  --client-text: #223041;
  --phone-text: #70839a;
  --idno-text: #7d8b9c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #f3f7fb 0%, #eef3f8 100%);
  color: var(--text);
}

.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #122033 0%, #17283d 100%);
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid rgba(255,255,255,0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--sidebar-soft);
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #60a5fa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.2);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
  color: #fff;
}

.brand p {
  margin: 3px 0 0;
  color: rgba(255,255,255,0.82);
  font-size: 12px;
}

.nav { display: flex; flex-direction: column; gap: 8px; }

.nav-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,0.6);
  margin: 4px 10px 6px;
}

.nav a {
  text-decoration: none;
  color: rgba(255,255,255,0.94);
  padding: 12px 14px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: .2s ease;
  font-weight: 500;
}

.nav a:hover,
.nav a.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.user-box {
  margin-top: auto;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.06);
  font-size: 13px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

.user-box strong { display: block; font-size: 14px; color: #fff; margin-bottom: 4px; }
.user-box span { color: rgba(255,255,255,0.84); }

.main { padding: 28px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters {
  padding: 18px;
  margin-bottom: 14px;
}

.filters-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--text);
}

.filters-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 7px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 14px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: .18s ease;
  box-shadow: inset 0 1px 2px rgba(17,24,39,0.02);
}

.field input:focus,
.field select:focus {
  border-color: #9bb7ef;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.create-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.btn {
  border: 0;
  border-radius: 13px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: .2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.btn-primary:hover { transform: translateY(-1px); }

.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1160px;
}

thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #3a4655;
  padding: 17px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

thead th:first-child { border-top-left-radius: 18px; }
thead th:last-child { border-top-right-radius: 18px; }

tbody td {
  padding: 15px 14px;
  border-bottom: 1px solid #edf2f7;
  vertical-align: middle;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}

tbody tr:hover td { background: #fbfdff; }

.invoice-no {
  display: block;
  font-weight: 600;
  color: var(--invoice-text);
  white-space: nowrap;
}

.date-under {
  display: block;
  font-size: 12px;
  color: var(--date-text);
  margin-top: 4px;
  font-weight: 500;
}

.subtext {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

tbody td:nth-child(3) {
  color: var(--client-text);
  font-weight: 500;
}

tbody td:nth-child(4) {
  color: var(--idno-text);
  font-weight: 500;
}

.amount {
  font-weight: 800;
  white-space: nowrap;
  color: #141c26;
  letter-spacing: 0.01em;
}

.status-select {
  min-width: 128px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  padding-right: 28px;
  box-shadow: var(--shadow-soft);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%2316202a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.status-select.unpaid {
  color: var(--warning);
  background-color: var(--warning-soft);
  border-color: #f6d77d;
}

.status-select.paid {
  color: var(--success);
  background-color: var(--success-soft);
  border-color: #9ce0b0;
}

.status-select.canceled {
  color: var(--danger);
  background-color: var(--danger-soft);
  border-color: #f4b199;
}

.note-cell { position: relative; }

details.note-popover {
  position: relative;
  display: inline-block;
}

details.note-popover summary {
  list-style: none;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid #b7cdf6;
  background: #edf4ff;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-soft);
}

details.note-popover summary::-webkit-details-marker { display: none; }

.note-box {
  position: absolute;
  top: 40px;
  right: 0;
  width: 300px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.14);
  padding: 14px;
  z-index: 20;
}

.note-title {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--text);
}

.note-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}

.note-empty {
  color: #9aa7b4;
  font-size: 16px;
}

.client-cell {
  line-height: 1.25;
}

.client-name {
  display: block;
  font-weight: 600;
  color: #1f2f3f;
}

.phone-subtext {
  display: block;
  font-size: 12px;
  color: #6f8094;
  margin-top: 4px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.idno-text {
  color: #667587;
  font-weight: 500;
}

.action-btn.delete-btn {
  color: #b42318;
  border-color: #f0c3bd;
  background: #fff7f6;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.delete-icon {
  font-size: 13px;
  line-height: 1;
  font-weight: 800;
}

.action-btn.delete-btn:hover {
  border-color: #e6a39a;
  background: #fff1ef;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.action-btn {
  padding: 8px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: .18s ease;
}

a.action-btn, a.btn, a.btn-primary, a.btn-secondary { text-decoration: none !important; }

.action-btn:hover {
  border-color: #c4d4ea;
  background: #f8fbff;
}

.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  color: var(--text);
  font-size: 13px;
}

.pagination { display: flex; gap: 8px; align-items: center; }

.page-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.page-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: transparent;
}

@media (max-width: 1200px) {
  .filters-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

@media (max-width: 700px) {
  .main { padding: 18px; }
  .filters-grid { grid-template-columns: 1fr; }
  .create-row, .footer-bar { flex-direction: column; align-items: flex-start; }
}

a { color: inherit; }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:18px; }
.topbar h2 { margin:0; font-size:26px; }
.topbar p { margin:4px 0 0; color:var(--muted); }
.alert { padding:13px 16px; border-radius:13px; margin-bottom:14px; border:1px solid var(--line); background:#fff; }
.alert-success { border-color:#9ce0b0; background:var(--success-soft); color:var(--success); }
.alert-error { border-color:#f4b199; background:var(--danger-soft); color:var(--danger); }
.form-card { padding:20px; margin-bottom:16px; }
.form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.form-grid.three { grid-template-columns:repeat(3,minmax(0,1fr)); }
.field textarea { width:100%; min-height:110px; border:1px solid var(--line); border-radius:13px; padding:12px 14px; font-size:14px; resize:vertical; font-family:inherit; }
.field textarea.mono { font-family:Consolas, monospace; min-height:190px; }
.field input[type="checkbox"] { width:auto; height:auto; }
.full { grid-column:1 / -1; }
.btn-secondary { background:#fff; color:var(--text); border:1px solid var(--line); box-shadow:var(--shadow-soft); text-decoration:none; }
.btn-danger { background:var(--danger); color:#fff; text-decoration:none; }
.btn-small { padding:8px 11px; border-radius:10px; font-size:12px; }
.inline-form { display:inline-flex; margin:0; }
.actions .btn, .actions .action-btn { text-decoration:none; }
.invoice-builder { display:grid; grid-template-columns:minmax(0,1.05fr) minmax(360px,.95fr); gap:18px; align-items:start; }
.section-title { margin:0 0 14px; font-size:18px; }
.items-table-form { width:100%; min-width:0; border-collapse:separate; border-spacing:0 8px; }
.items-table-form th { position:static; background:transparent; border:0; padding:0 8px 4px; color:var(--muted); }
.items-table-form td { border:0; background:transparent; padding:0 6px; }
.items-table-form input { width:100%; height:40px; border:1px solid var(--line); border-radius:10px; padding:0 10px; }
.item-total { font-weight:800; white-space:nowrap; }
.add-row-wrap { display:flex; justify-content:flex-end; margin-top:10px; }
.calc-stats { display:flex; justify-content:space-between; gap:12px; margin:10px 0; color:var(--muted); font-weight:700; }
.preview-box { background:#fff; border:1px solid var(--line); border-radius:14px; padding:14px; min-height:420px; overflow:auto; }
.email-box textarea { min-height:150px; }
.auth-shell { min-height:100vh; display:grid; place-items:center; padding:24px; background:#eef3f8; }
.auth-card { width:min(430px,100%); padding:26px; }
.auth-brand { text-align:center; margin-bottom:20px; }
.auth-brand .brand-logo { margin:0 auto 10px; color:#fff; }
.muted { color:var(--muted); }
.badge { display:inline-flex; align-items:center; border-radius:999px; padding:5px 10px; font-size:12px; font-weight:800; }
.badge.admin { background:#e8f0ff; color:#1d4ed8; }
.badge.accountant { background:#ebfbef; color:#15803d; }
.badge.operator { background:#fff8e6; color:#a16207; }
.badge.inactive { background:#f3f4f6; color:#6b7280; }
.pagination nav, .pagination .hidden { display:block; }
.template-grid { display:grid; grid-template-columns:minmax(0,1fr) minmax(360px,.8fr); gap:18px; align-items:start; }