/* Scaffbook Scaffold Register — UI styles */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --line: #2a2f3a;
  --text: #e7eaf0;
  --muted: #99a1b3;
  --accent: #3f6fb5;      /* Scaffbook brand blue */
  --accent-2: #5b88cf;
  --green: #34c759;
  --yellow: #ffd60a;
  --red: #ff453a;
  --blue: #4aa3ff;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-title { font-weight: 700; letter-spacing: .3px; font-size: 17px; }
.brand-title .wm-scaff { color: #93a4c8; }
.brand-title .wm-book  { color: #eef1f6; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: #fff; background: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: #3a4150; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #5a2b2b; }
.btn.danger:hover { background: #2a1818; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* Layout */
main { padding: 22px; max-width: 1200px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; position: relative; overflow: hidden;
}
.stat .n { font-size: 30px; font-weight: 700; line-height: 1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 8px; }
.stat.alert .n { color: var(--red); }
.stat.warn .n { color: var(--yellow); }
.stat.good .n { color: var(--green); }
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line); }
.stat.alert::after { background: var(--red); }
.stat.warn::after { background: var(--yellow); }
.stat.good::after { background: var(--green); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: baseline; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 16px; }

.attention-list { display: flex; flex-direction: column; }
.att {
  display: grid; grid-template-columns: 90px 1fr auto; gap: 14px; align-items: center;
  padding: 12px 18px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.att:last-child { border-bottom: 0; }
.att:hover { background: var(--surface-2); }
.att .ref { font-weight: 700; }
.att .meta { color: var(--muted); font-size: 13px; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; min-width: 220px; }
input, select, textarea {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 14px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.select { width: auto; min-width: 170px; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); }
.grid td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.ref-cell { font-weight: 700; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge.green { background: rgba(52,199,89,.14); color: var(--green); border-color: rgba(52,199,89,.3); }
.badge.yellow { background: rgba(255,214,10,.14); color: var(--yellow); border-color: rgba(255,214,10,.3); }
.badge.red { background: rgba(255,69,58,.15); color: var(--red); border-color: rgba(255,69,58,.35); }
.badge.blue { background: rgba(74,163,255,.14); color: var(--blue); border-color: rgba(74,163,255,.3); }
.badge.grey { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); } .dot.yellow { background: var(--yellow); } .dot.red { background: var(--red); }

/* Drawer */
.drawer, .modal { position: fixed; inset: 0; z-index: 50; }
.hidden { display: none !important; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  overflow-y: auto; padding: 22px; animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.drawer-head h2 { margin: 0; font-size: 22px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 16px 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 22px 0 10px; border-top: 1px solid var(--line); padding-top: 16px; }

/* Inspection history */
.insp { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface-2); }
.insp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.insp-date { font-weight: 700; }
.insp-meta { color: var(--muted); font-size: 13px; }
.insp p { margin: 6px 0 0; font-size: 14px; }
.insp .defects { color: var(--yellow); }

/* Modal */
.modal-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(620px, 94vw); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.modal-card h2 { margin: 0 0 16px; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 22px; line-height: 1; padding: 4px 8px; }
.icon-btn:hover { color: var(--text); }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 80; font-weight: 600;
}
.toast.err { border-color: var(--red); color: #ffd0cc; }

/* Login screen */
.auth-view {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px calc(24px + env(safe-area-inset-right)) 24px calc(24px + env(safe-area-inset-left));
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(63,111,181,.18), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px;
}
.auth-brand { margin-bottom: 18px; }
.auth-card h1 { margin: 6px 0 18px; font-size: 20px; }
.auth-card .field { margin-bottom: 14px; }
.auth-submit { width: 100%; justify-content: center; margin-top: 4px; }
.auth-error {
  background: rgba(255,69,58,.12); border: 1px solid rgba(255,69,58,.35); color: #ffd0cc;
  padding: 9px 11px; border-radius: 8px; font-size: 13px; margin-bottom: 12px;
}
.link-btn {
  display: block; width: 100%; margin-top: 14px; background: transparent; border: 0;
  color: var(--accent-2); cursor: pointer; font-size: 13px; font-weight: 600; text-align: center;
}
.link-btn:hover { text-decoration: underline; }

/* User menu */
.user-menu { position: relative; }
.user-chip { max-width: 220px; }
.user-chip #user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px; min-width: 150px; z-index: 30;
}
.user-dropdown .link-btn { margin: 0; padding: 8px 10px; color: var(--text); text-align: left; border-radius: 6px; }
.user-dropdown .link-btn:hover { background: var(--surface-2); text-decoration: none; }

/* PWA: respect device safe areas in standalone mode */
.topbar { padding-top: calc(12px + env(safe-area-inset-top)); }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .user-menu { margin-left: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .grid th:nth-child(3), .grid td:nth-child(3),
  .grid th:nth-child(4), .grid td:nth-child(4) { display: none; }
}
