@import url('vars.css');

body.admin { background: var(--paper); }

/* ---------- Auth / login screen ---------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(176,141,87,0.18), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(176,141,87,0.12), transparent 45%),
    linear-gradient(160deg, var(--ink-navy-deep), var(--ink-navy) 60%, var(--ink-navy-soft));
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  padding: 40px 34px 34px;
  position: relative;
  overflow: hidden;
}

.auth-seal {
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 2px dashed var(--brass);
  display: grid; place-items: center;
  margin: 0 auto 18px;
  position: relative;
}
.auth-seal::before {
  content: '';
  position: absolute; inset: 8px;
  border: 1px solid var(--brass-light);
  border-radius: 50%;
}
.auth-seal span {
  font-weight: 800; font-size: 22px; color: var(--brass-dark);
  transform: rotate(-8deg);
}

.auth-title { text-align: center; font-size: 20px; font-weight: 800; color: var(--ink-navy); margin: 0 0 4px; }
.auth-sub { text-align: center; font-size: 13px; color: var(--ink-gray); margin: 0 0 28px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-gray); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--paper-line);
  background: var(--white);
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  min-height: 46px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 4px rgba(176,141,87,0.15);
}
.field textarea { resize: vertical; min-height: 70px; }
.field input.invalid { border-color: var(--seal-red); }
.field input.invalid:focus { box-shadow: 0 0 0 4px rgba(161,61,61,0.15); }
.field-error-text { font-size: 11.5px; color: var(--seal-red); margin-top: 5px; display: none; }
.field-error-text.show { display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .15s;
  font-family: inherit;
  min-height: 44px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--brass), var(--brass-dark)); color: var(--white); box-shadow: 0 8px 20px -8px rgba(138,108,63,0.6); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-navy { background: var(--ink-navy); color: var(--white); }
.btn-navy:hover { background: var(--ink-navy-soft); }
.btn-ghost { background: transparent; color: var(--ink-navy); border: 1.5px solid var(--paper-line); }
.btn-ghost:hover { border-color: var(--brass); color: var(--brass-dark); }
.btn-danger { background: var(--seal-red-soft); color: var(--seal-red); }
.btn-danger:hover { background: #ecd3d0; }
.btn-amber { background: var(--seal-amber-soft); color: var(--seal-amber); }
.btn-amber:hover { background: #f5e6bd; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 12.5px; border-radius: 7px; min-height: 36px; }

.auth-error {
  background: var(--seal-red-soft); color: var(--seal-red);
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px;
}

/* ---------- App shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(190deg, var(--ink-navy-deep), var(--ink-navy) 75%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
}
.mobile-topbar .mt-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 14px; }
.mobile-topbar .mt-brand .dot { width: 32px; height: 32px; border-radius: 50%; border: 2px dashed var(--brass-light); display: grid; place-items: center; color: var(--brass-light); font-size: 12px; font-weight: 800; }
.hamburger-btn {
  width: 40px; height: 40px; border-radius: 10px; border: none;
  background: rgba(255,255,255,0.08); color: #fff; font-size: 18px; cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(14,23,48,0.55);
  z-index: 45;
}
.sidebar-overlay.open { display: block; }

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: linear-gradient(190deg, var(--ink-navy-deep), var(--ink-navy) 75%);
  color: #dfe4f2;
  padding: 26px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 4px 24px; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 22px; }
.brand-seal {
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px dashed var(--brass-light);
  display: grid; place-items: center;
  color: var(--brass-light); font-weight: 800; font-size: 15px;
  transform: rotate(-6deg);
  flex-shrink: 0;
}
.brand-name { font-weight: 800; font-size: 16px; color: #fff; }
.brand-tag { font-size: 11px; color: #93a0c2; letter-spacing: .04em; }

.nav-group { margin-bottom: 22px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #6b7796; margin: 0 8px 8px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 10px;
  font-size: 14px; font-weight: 600; color: #c7cee3;
  margin-bottom: 4px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: linear-gradient(135deg, rgba(176,141,87,0.35), rgba(176,141,87,0.12)); color: #fff; box-shadow: inset 0 0 0 1px rgba(217,190,143,0.35); }
.nav-icon { width: 18px; text-align: center; opacity: .9; }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user { font-size: 13px; color: #c7cee3; margin-bottom: 10px; }
.sidebar-user b { color: #fff; }

.main { flex: 1; min-width: 0; padding: 30px 36px 60px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 800; color: var(--ink-navy); margin: 0; }
.page-sub { font-size: 13px; color: var(--ink-gray); margin: 4px 0 0; }

/* ---------- Stat cards ---------- */

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat-card {
  background: var(--paper-raised); border-radius: var(--radius-md);
  padding: 18px 20px; box-shadow: var(--shadow-soft);
  border: 1px solid var(--paper-line);
  min-width: 0;
}
.stat-card .k { font-size: 12px; color: var(--ink-gray); font-weight: 600; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-card .v { font-size: 22px; font-weight: 800; color: var(--ink-navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-card.accent .v { color: var(--brass-dark); }
.stat-card.good .v { color: var(--seal-green); }
.stat-card.bad .v { color: var(--seal-red); }
.stat-card.warn .v { color: var(--seal-amber); }

/* ---------- Panel / filters ---------- */

.panel { background: var(--paper-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); border: 1px solid var(--paper-line); overflow: hidden; }
.panel-head { padding: 18px 22px; border-bottom: 1px solid var(--paper-line); display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 800; color: var(--ink-navy); }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; width: 100%; }
.filters .chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap input[type=text] {
  padding: 10px 38px 10px 14px; border-radius: 10px; border: 1.5px solid var(--paper-line);
  font-size: 14px; width: 100%; font-family: inherit; min-height: 42px;
}
.search-wrap input:focus { outline: none; border-color: var(--brass); }
.search-spinner {
  position: absolute; top: 50%; right: 12px; transform: translateY(-50%);
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--paper-line); border-top-color: var(--brass);
  opacity: 0; transition: opacity .15s;
  animation: spin .7s linear infinite;
}
.search-wrap.loading .search-spinner { opacity: 1; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

.chip { padding: 8px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 700; border: 1.5px solid var(--paper-line); color: var(--ink-gray); cursor: pointer; background: var(--white); white-space: nowrap; }
.chip.active { background: var(--ink-navy); color: #fff; border-color: var(--ink-navy); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.paid { background: var(--seal-green-soft); color: var(--seal-green); }
.badge.unpaid { background: var(--seal-red-soft); color: var(--seal-red); }
.badge.partial { background: var(--seal-amber-soft); color: var(--seal-amber); }
.badge.cancelled { background: var(--seal-gray-soft); color: var(--seal-gray); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  border: 1.5px solid var(--paper-line); color: var(--ink-gray); background: var(--white);
  cursor: pointer; transition: all .15s; flex-shrink: 0; font-size: 15px;
}
.icon-btn:hover { border-color: var(--brass); color: var(--brass-dark); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-gray); }
.empty-state .em-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h4 { color: var(--ink-navy); margin: 0 0 6px; }

/* ---------- Invoice list rows (replaces the old table; same markup works on all screens) ---------- */

#invoice-list-container { position: relative; min-height: 60px; }

.inv-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--paper-line);
}
.inv-row:last-child { border-bottom: none; }
.inv-row:hover { background: #fbf9f2; }

.inv-main { min-width: 0; }
.inv-top-line { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; flex-wrap: wrap; }
.inv-number { font-weight: 800; color: var(--ink-navy); font-size: 14px; direction: ltr; display: inline-block; }
.inv-buyer { font-size: 13.5px; color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-meta { font-size: 11.5px; color: var(--ink-faint); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.inv-amount { text-align: center; white-space: nowrap; }
.inv-amount .amt { font-weight: 800; color: var(--ink-navy); font-size: 14px; }
.inv-amount .due { font-size: 11px; color: var(--seal-amber); margin-top: 2px; font-weight: 700; }
.inv-amount .cur { font-size: 10.5px; color: var(--ink-faint); }

.inv-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 760px) {
  .inv-row { grid-template-columns: 1fr; gap: 10px; padding: 16px; }
  .inv-amount { text-align: right; }
  .inv-actions { justify-content: flex-start; }
}

/* ---------- Invoice builder ---------- */

.builder-grid { display: grid; grid-template-columns: 1fr 360px; gap: 22px; align-items: start; }
@media (max-width: 1100px) { .builder-grid { grid-template-columns: 1fr; } }

.payment-section-wrap { margin-top: 8px; }

.card { background: var(--paper-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); border: 1px solid var(--paper-line); padding: 22px; margin-bottom: 20px; }
.card h3 { margin: 0 0 16px; font-size: 14.5px; font-weight: 800; color: var(--ink-navy); display: flex; align-items: center; gap: 8px; }
.card h3 .num { width: 22px; height: 22px; border-radius: 50%; background: var(--brass-light); color: var(--ink-navy-deep); font-size: 11px; display: grid; place-items: center; flex-shrink: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* item cards (mobile-first, generously sized inputs) */
.item-card {
  border: 1.5px solid var(--paper-line);
  border-radius: 14px;
  padding: 14px 14px 12px;
  margin-bottom: 14px;
  background: var(--white);
}
.item-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.item-card-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brass-light);
  display: grid; place-items: center; font-size: 11.5px; font-weight: 800; color: var(--ink-navy-deep);
  flex-shrink: 0;
}
.item-title-input { flex: 1; font-weight: 700; min-width: 0; }
.item-sub-input { margin-bottom: 10px; }
.item-title-input, .item-sub-input {
  width: 100%; padding: 11px 12px; border-radius: 9px; border: 1.5px solid var(--paper-line);
  font-family: inherit; font-size: 15px; background: var(--white); min-height: 44px;
}
.item-title-input:focus, .item-sub-input:focus { outline: none; border-color: var(--brass); }

.item-card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
@media (max-width: 560px) { .item-card-grid { grid-template-columns: repeat(2, 1fr); } }

.micro-field label { font-size: 10.5px; color: var(--ink-faint); display: block; margin-bottom: 4px; font-weight: 700; }
.micro-field input {
  width: 100%; padding: 11px 10px; border-radius: 9px; border: 1.5px solid var(--paper-line);
  font-family: inherit; font-size: 15px; background: var(--white); min-height: 44px; text-align: center;
}
.micro-field input:focus { outline: none; border-color: var(--brass); }
.micro-field.total-field { display: flex; flex-direction: column; }
.micro-field.total-field .f-line-total {
  font-weight: 800; color: var(--ink-navy); text-align: center; padding-top: 10px; font-size: 15px;
}

.removable-check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-gray); cursor: pointer; }
.removable-check input { width: 17px; height: 17px; accent-color: var(--brass); flex-shrink: 0; }

.row-remove-btn {
  width: 36px; height: 36px; border-radius: 9px; border: 1.5px solid var(--paper-line);
  background: var(--white); color: var(--seal-red); cursor: pointer; flex-shrink: 0; font-size: 16px;
}
.row-remove-btn:hover { background: var(--seal-red-soft); }

.add-row-btn {
  margin-top: 4px; padding: 12px 16px; border-radius: 12px; border: 1.5px dashed var(--brass);
  background: transparent; color: var(--brass-dark); font-weight: 700; font-size: 13.5px; cursor: pointer; width: 100%;
  min-height: 46px;
}
.add-row-btn:hover { background: rgba(176,141,87,0.08); }

/* asset picker */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.asset-swatch {
  border: 2px solid var(--paper-line); border-radius: 12px; padding: 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  transition: all .15s; background: var(--white);
}
.asset-swatch img { width: 100%; height: 46px; object-fit: contain; }
.asset-swatch span { font-size: 10.5px; color: var(--ink-gray); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.asset-swatch.selected { border-color: var(--brass); box-shadow: 0 0 0 3px rgba(176,141,87,0.18); background: #fffaf0; }
.asset-swatch.none-option { justify-content: center; height: 100%; color: var(--ink-faint); font-size: 12px; }

/* sticky preview / totals panel */
.sticky-panel { position: sticky; top: 22px; }
.preview-total { background: linear-gradient(160deg, var(--ink-navy-deep), var(--ink-navy)); color: #fff; border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow-lift); }
.preview-total .pt-row { display: flex; justify-content: space-between; font-size: 13px; color: #b9c1dc; padding: 6px 0; gap: 10px; }
.preview-total .pt-row.grand { border-top: 1px dashed rgba(255,255,255,0.25); margin-top: 8px; padding-top: 14px; font-size: 18px; font-weight: 800; color: #fff; }
.preview-total .pt-row.grand .amt { color: var(--brass-light); }

.upload-inline { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.upload-inline input[type=text] { flex: 1; min-width: 140px; }

form .field-hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 5px; line-height: 1.7; }

.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.toast-banner { background: var(--seal-green-soft); color: var(--seal-green); padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 700; margin-bottom: 18px; display: flex; align-items: center; gap: 8px; }

.copy-link-box { display: flex; gap: 8px; align-items: center; background: #fbf9f2; border: 1.5px dashed var(--paper-line); border-radius: 10px; padding: 10px 14px; margin-top: 6px; }
.copy-link-box code { flex: 1; font-size: 12.5px; color: var(--ink-navy); overflow-x: auto; white-space: nowrap; direction: ltr; text-align: left; }

.meta-line { font-size: 12px; color: var(--ink-faint); margin-top: 6px; }
.meta-line b { color: var(--ink-gray); }

/* ---------- SMS ---------- */

.sms-success-text { color: var(--seal-green); font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.sms-error-text { color: var(--seal-red); font-weight: 700; font-size: 12.5px; margin-top: 10px; background: var(--seal-red-soft); padding: 10px 12px; border-radius: 8px; }
.sms-hint-text { color: var(--ink-faint); font-size: 12px; margin-top: 10px; line-height: 1.8; }

/* ---------- payment management ---------- */

.pay-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.pay-summary .ps-box { background: #fbf9f2; border: 1px solid var(--paper-line); border-radius: 10px; padding: 12px; text-align: center; }
.pay-summary .ps-box .k { font-size: 11px; color: var(--ink-faint); font-weight: 700; margin-bottom: 4px; }
.pay-summary .ps-box .v { font-size: 15px; font-weight: 800; color: var(--ink-navy); }
.pay-summary .ps-box.due .v { color: var(--seal-amber); }
@media (max-width: 480px) { .pay-summary { grid-template-columns: 1fr; } }

.pay-item-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--paper-line); flex-wrap: wrap; }
.pay-item-row:last-child { border-bottom: none; }
.pay-item-title { flex: 1; min-width: 140px; font-size: 13px; font-weight: 700; color: var(--ink); }
.pay-item-title .muted { display: block; font-size: 11px; color: var(--ink-faint); font-weight: 500; margin-top: 2px; }
.pay-amount-input { width: 130px; padding: 9px 10px; border-radius: 8px; border: 1.5px solid var(--paper-line); font-family: inherit; font-size: 14px; text-align: center; min-height: 40px; }
.pay-amount-input:focus { outline: none; border-color: var(--brass); }

/* ---------- modal ---------- */

.modal-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(14,23,48,0.6);
  z-index: 100; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--paper-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-lift);
  max-width: 380px; width: 100%; padding: 28px 24px 24px; text-align: center;
  animation: modalpop .18s ease;
}
@keyframes modalpop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-icon {
  width: 56px; height: 56px; border-radius: 50%; background: var(--seal-amber-soft); color: var(--seal-amber);
  display: grid; place-items: center; font-size: 24px; margin: 0 auto 16px;
}
.modal-title { font-size: 16px; font-weight: 800; color: var(--ink-navy); margin: 0 0 8px; }
.modal-text { font-size: 13px; color: var(--ink-gray); line-height: 1.9; margin: 0 0 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ---------- mobile ---------- */

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }
  .mobile-topbar { display: flex; }
  .sidebar.drawer-open {
    display: flex;
    position: fixed; top: 0; bottom: 0; right: 0; width: 84%; max-width: 300px;
    z-index: 50; height: 100vh; box-shadow: -20px 0 40px rgba(0,0,0,0.35);
    animation: slidein .2s ease;
  }
  @keyframes slidein { from { transform: translateX(100%); } to { transform: translateX(0); } }
  .main { padding: 18px 14px 50px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .topbar .toolbar-actions { width: 100%; }
  .topbar .toolbar-actions .btn { flex: 1; }
}
