:root {
  --bg: #0f1720;
  --panel: #17212b;
  --panel-2: #1e2a36;
  --line: #2b3947;
  --text: #e7edf3;
  --muted: #8ea0b2;
  --primary: #2f81f7;
  --primary-2: #1f6fe0;
  --green: #2ea043;
  --red: #e5534b;
  --amber: #d29922;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); margin-top: 8px; min-height: 18px; font-size: 14px; }
a { color: var(--primary); }

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #24323f; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--red); color: #ff9d96; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
textarea { resize: vertical; min-height: 90px; font-family: inherit; }
.login-card .btn { width: 100%; margin-top: 18px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; }
.tabs { display: flex; gap: 8px; margin-left: 8px; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: #fff; background: var(--panel-2); border-color: var(--line); }
.tab.primary { color: #fff; background: var(--primary); }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* Content */
main { padding: 22px; max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; }

/* Table */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table { width: 100%; min-width: 560px; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tr.clickable:hover td { background: var(--panel-2); cursor: pointer; }

.badge { padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-block; }
.badge.draft { background: #33291a; color: var(--amber); }
.badge.signed { background: #16301c; color: #56d364; }
.badge.emailed { background: #142a3f; color: #58a6ff; }

/* Grid / forms */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.section { margin-top: 18px; }
.section h3 { margin: 0 0 6px; font-size: 15px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

/* Signature pad */
.sigpad-wrap { background: #fff; border-radius: 10px; padding: 6px; }
canvas.sigpad { width: 100%; height: 180px; touch-action: none; display: block; border-radius: 6px; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.photo-tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.photo-tile img { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo-tile .cap { padding: 6px 8px; font-size: 12px; display: flex; justify-content: space-between; align-items: center; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; }
.modal { width: 480px; max-width: 100%; max-height: 90vh; overflow: auto; }
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 10px; z-index: 40; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }

/* Responsive */
@media (max-width: 720px) {
  main { padding: 14px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 10px 12px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; gap: 6px; padding-bottom: 2px; }
  .tabs .tab { flex: 0 0 auto; white-space: nowrap; }
  .account { margin-left: auto; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .grid, .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .kv { grid-template-columns: 120px 1fr; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

@media (max-width: 480px) {
  .topbar { gap: 8px 10px; }
  .brand { font-size: 15px; }
  .account #admin-name { display: none; }
  .btn { padding: 8px 10px; font-size: 13px; }
  main { padding: 10px; }
  .login-card { max-width: 100%; }
}
