/* ===== WebFly CRM — style ===== */
:root {
  --red: #d61f2c;
  --red-dark: #b11723;
  --ink: #1c2128;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f5f7;
  --card: #ffffff;
  --green: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

/* ===== Top bar ===== */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  height: 42px;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: .2px; }
.brand-name span { color: var(--red); }
.brand-sub { font-size: 11.5px; color: var(--muted); }

/* ===== Layout ===== */
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: var(--red);
}
.stat-card.accent::before { background: var(--green); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 2px; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.search-box {
  flex: 1 1 240px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.search-box input {
  border: none; outline: none;
  padding: 10px 0;
  font-size: 14px;
  width: 100%;
  background: transparent;
  color: var(--ink);
}
.filter-select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  outline: none;
  cursor: pointer;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, box-shadow .15s ease, transform .05s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 2px 6px rgba(214,31,44,.3); }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f9fafb; }
.btn-new { padding: 9px 14px; }
.btn[disabled] { opacity: .6; cursor: wait; }

/* ===== Sheet (Excel-like table) ===== */
.sheet-shell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sheet-scroll { overflow-x: auto; }
.sheet {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
.sheet thead th {
  position: sticky;
  top: 0;
  background: #fafbfc;
  border-bottom: 2px solid var(--line);
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  padding: 10px 12px;
  z-index: 2;
  user-select: none;
}
.sheet tbody td {
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  font-size: 14px;
  vertical-align: middle;
  background: #fff;
}
.sheet tbody tr:hover td { background: #fafbfc; }
.sheet tbody tr.flash td { animation: flash 1.2s ease; }
@keyframes flash {
  0% { background: #ffe9ea; }
  100% { background: #fff; }
}

.col-rownum { width: 46px; color: var(--muted); text-align: center !important; font-weight: 600; }
.col-actions { white-space: nowrap; width: 128px; }
.col-date { white-space: nowrap; }

/* Editable cells */
.cell-edit {
  outline: none;
  min-height: 24px;
  border-radius: 6px;
  padding: 4px 6px;
  margin: -4px -6px;
  cursor: text;
  transition: box-shadow .12s ease;
  word-break: break-word;
}
.cell-edit:hover { box-shadow: inset 0 0 0 1px #d3d7dd; }
.cell-edit:focus { box-shadow: inset 0 0 0 2px var(--red); }
.cell-edit:empty::before { content: attr(data-ph); color: #b6bcc4; }
.cell-saved { animation: savedPulse .8s ease; }
@keyframes savedPulse {
  0% { box-shadow: inset 0 0 0 2px var(--green); }
  100% { box-shadow: inset 0 0 0 2px transparent; }
}

/* Inline select */
.cell-select {
  border: 1px solid transparent;
  background: transparent;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  max-width: 190px;
  color: var(--ink);
}
.cell-select:hover, .cell-select:focus { border-color: var(--red); outline: none; }

/* Row action buttons */
.row-actions { display: flex; gap: 6px; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s ease;
}
.icon-btn:hover { border-color: var(--red); color: var(--red); background: #fff5f5; }
.icon-btn.danger:hover { border-color: var(--red); background: var(--red); color: #fff; }
.icon-btn svg { width: 15px; height: 15px; }

/* Loading / empty */
.loading-row td { text-align: center; color: var(--muted); padding: 34px 12px; }
.empty-state {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.empty-icon { color: #c3c9d1; display: flex; justify-content: center; margin-bottom: 10px; }
.empty-state h3 { color: var(--ink); margin-bottom: 4px; }

/* ===== Modal ===== */
.modal-overlay[hidden] { display: none; } /* fix: author display:flex must not beat the hidden attribute */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  animation: slideUp .18s ease;
}
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 10px;
}
.modal-head h2 { font-size: 18px; }
.modal-close {
  border: none; background: none;
  font-size: 26px; line-height: 1;
  color: var(--muted); cursor: pointer;
  padding: 2px 8px;
  border-radius: 8px;
}
.modal-close:hover { background: #f1f2f4; color: var(--ink); }
.modal-body { padding: 6px 20px 20px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.free-hint { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.form-row input, .form-row textarea, .form-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
  background: #fff;
  color: var(--ink);
}
.form-row input:focus, .form-row textarea:focus, .form-row select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(214,31,44,.12);
}
.modal-foot { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.pdf-hint {
  display: flex; align-items: center; gap: 7px;
  background: #fff5f5;
  border: 1px solid #ffd6d9;
  color: var(--red-dark);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 10px;
}
.modal-btns { display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Toast ===== */
.toast-wrap {
  position: fixed;
  right: 16px; bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  gap: 9px;
  animation: toastIn .2s ease;
  max-width: 340px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.hide { animation: toastOut .25s ease forwards; }
@keyframes toastOut { to { transform: translateY(8px); opacity: 0; } }

/* ===== Footer ===== */
.foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 26px; }

/* ===== Topbar right (user menu) ===== */
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f4f5f7; border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 12px;
  font-size: 13px; font-weight: 600; color: var(--ink);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
a.btn { text-decoration: none; }

/* ===== Account card (below report sheet) ===== */
.account-card {
  margin-top: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.account-info { display: flex; align-items: center; gap: 12px; }
.account-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff5f5; color: var(--red);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #ffd6d9;
}
.account-title { font-weight: 800; font-size: 15px; }
.account-sub { font-size: 13px; color: var(--muted); }
.account-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Login page ===== */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #fff 0%, #f4f5f7 55%, #ffe9ea 100%);
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(16,24,40,.12);
  padding: 30px 28px;
  text-align: center;
}
.login-logo { height: 64px; width: auto; object-fit: contain; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; font-weight: 800; }
.login-card h1 span { color: var(--red); }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 2px 0 18px; }
.login-form { text-align: left; }
.btn-block { width: 100%; justify-content: center; margin-top: 4px; }
.login-error {
  background: #fff5f5; border: 1px solid #ffb3b8; color: var(--red-dark);
  font-size: 13.5px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px;
}
.login-hint {
  margin-top: 16px; font-size: 12.5px; color: var(--muted);
  background: #f8f9fb; border: 1px dashed var(--line);
  border-radius: 10px; padding: 10px 12px; line-height: 1.6;
}
.login-foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 16px; }

/* ===== Checkboxes (bulk PDF selection) ===== */
.col-check { width: 46px; text-align: center !important; }
.row-check, #checkAll { width: 16px; height: 16px; accent-color: var(--red); cursor: pointer; vertical-align: middle; }

/* ===== Badge (selected count) ===== */
.badge { background: rgba(255,255,255,.25); border-radius: 999px; padding: 1px 8px; font-size: 12px; }

/* ===== White report sheet ===== */
.sheet-preview-wrap { margin-top: 22px; }
.section-title { margin-bottom: 10px; }
.section-title h2 { font-size: 16px; }
.section-title p { font-size: 12.5px; color: var(--muted); }
.paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 26px 30px;
  min-height: 260px;
}
.paper-head { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid var(--red); padding-bottom: 12px; flex-wrap: wrap; }
.paper-logo { height: 46px; width: auto; object-fit: contain; }
.paper-head-main { flex: 1; min-width: 140px; }
.paper-title { font-size: 20px; font-weight: 800; }
.paper-sub { font-size: 12px; color: var(--muted); }
.paper-meta { font-size: 12.5px; color: var(--muted); text-align: right; display: flex; flex-direction: column; gap: 2px; }
.paper-body { padding: 16px 0; overflow-x: auto; }
.paper-empty { text-align: center; color: var(--muted); padding: 44px 10px; font-size: 14px; }
.paper-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.paper-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--red-dark); border-bottom: 1px solid var(--line); padding: 8px 10px; }
.paper-table td { border-bottom: 1px solid var(--line); padding: 8px 10px; font-size: 13.5px; }
.paper-table tr:hover td { background: #fafbfc; }
.paper-foot { text-align: center; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); padding-top: 10px; }
.sheet-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* ===== Responsive: card view on small screens ===== */
@media (max-width: 720px) {
  .brand-sub { display: none; }
  .brand-name { font-size: 16px; }
  .brand-logo { height: 36px; }

  .sheet-scroll { overflow-x: visible; }
  .sheet { min-width: 0; }
  .sheet thead { display: none; }
  .sheet, .sheet tbody, .sheet tr, .sheet td { display: block; width: 100%; }
  .sheet tbody tr {
    border-bottom: 2px solid var(--line);
    padding: 6px 0;
  }
  .sheet tbody td {
    border-bottom: none;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    text-align: right;
  }
  .sheet tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    font-weight: 700;
    color: var(--muted);
    text-align: left;
    flex: 0 0 auto;
  }
  .col-rownum { display: none; }
  .col-actions { width: 100% !important; }
  .row-actions { justify-content: flex-end; }
  .cell-select { max-width: 55vw; text-align: right; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .btn { justify-content: center; }
  .search-box { flex: 1 1 auto; }

  .paper { padding: 18px 14px; }
  .paper-head { gap: 10px; }
  .paper-meta { text-align: left; }

  .hide-sm { display: none; }
  .topbar { padding: 10px 12px; }
  .account-btns { width: 100%; }
  .account-btns .btn { flex: 1; justify-content: center; }
}
