:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242d;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --primary: #5b8cff;
    --primary-ink: #fff;
    --warn: #f0a52a;
    --ok: #3ecf8e;
    --danger: #ff6b6b;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: #3a4150; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-warn { background: transparent; border-color: var(--warn); color: var(--warn); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger { background: transparent; border-color: rgba(255, 107, 107, .35); color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn.full { width: 100%; }
.inline { display: inline; }

/* ---------- PIN / login screen ---------- */
.pin-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: radial-gradient(1200px 600px at 50% -10%, #1b2030 0%, var(--bg) 60%);
}
.pin-modal {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem 1.75rem 1.75rem;
    text-align: center;
}
.pin-modal h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.pin-sub { margin: 0 0 1.5rem; color: var(--muted); font-size: .92rem; }

.pin-dots { display: flex; gap: .8rem; justify-content: center; margin-bottom: 1rem; }
.pin-dots .dot {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid #3a4150; transition: background .12s ease, border-color .12s ease;
}
.pin-dots .dot.filled { background: var(--primary); border-color: var(--primary); }

.pin-error { color: var(--danger); font-size: .85rem; min-height: 1.2em; margin: 0 0 .75rem; visibility: hidden; }
.pin-error.show { visibility: visible; }
.pin-screen.shake .pin-modal { animation: shake .4s; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .65rem;
    margin-top: .5rem;
}
.keypad button {
    aspect-ratio: 1 / 1;
    font-size: 1.4rem;
    font-weight: 600;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: transform .05s ease, background .15s ease;
}
.keypad button:hover { background: #262b35; }
.keypad button:active { transform: scale(.94); }
.keypad .keypad-ghost { background: transparent; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack input, .pin-modal input[type=password] {
    width: 100%; padding: .7rem .9rem; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}

/* ---------- top bar + layout ---------- */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-inner {
    max-width: 1100px; margin: 0 auto; padding: .85rem 1.25rem;
    display: flex; align-items: center; gap: 1rem;
}
.brand { font-weight: 700; }
.who { color: var(--muted); margin-left: auto; }
.topbar .btn { padding: .4rem .8rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.empty { color: var(--muted); padding: 2rem 0; }
.muted { color: var(--muted); }

/* ---------- preview list ---------- */
.preview-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.preview-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.25rem;
}
.preview-link { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.preview-title { font-weight: 600; font-size: 1.05rem; }
.preview-comment { color: var(--muted); margin: .5rem 0 0; font-style: italic; }

.badge { font-size: .78rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px; white-space: nowrap; }
.badge-pending { background: #2a2f3a; color: var(--muted); }
.badge-approved { background: rgba(62, 207, 142, .15); color: var(--ok); }
.badge-changes { background: rgba(240, 165, 42, .15); color: var(--warn); }

/* ---------- viewer + feedback drawer ---------- */
.viewer { --drawer-w: 360px; position: relative; height: calc(100vh - 56px); overflow: hidden; }
.viewer-frame { background: #fff; width: 100%; height: 100%; }
.viewer-frame iframe { width: 100%; height: 100%; border: 0; }

/* The drawer slides in from the right, overlaying the preview. */
.viewer-side {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: var(--drawer-w); max-width: 92vw;
    background: var(--surface); border-left: 1px solid var(--border);
    padding: 1.5rem; overflow-y: auto;
    transform: translateX(100%);
    transition: transform .25s ease;
    box-shadow: -12px 0 30px rgba(0, 0, 0, .3);
}
.viewer.drawer-open .viewer-side { transform: translateX(0); }

.viewer-side h2 { margin-top: 0; font-size: 1.1rem; }
.viewer-side label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.viewer-side textarea {
    width: 100%; padding: .7rem .9rem; border-radius: 10px; resize: vertical;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}
.feedback-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .9rem 0 .6rem; }
.small { font-size: .8rem; }

/* comment thread (client drawer) */
.comment-thread { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1.25rem; max-height: 45%; overflow-y: auto; }
.comment { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .65rem .8rem; }
.comment-author { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; margin-bottom: .25rem; color: var(--muted); }
.comment-body { margin: 0; white-space: pre-wrap; word-break: break-word; }
.comment-time { display: block; margin-top: .35rem; font-size: .75rem; color: var(--muted); }
.comment-empty { margin: 0 0 1rem; }

/* admin replies stand apart from client comments on both views */
.comment-admin { border-left: 3px solid var(--primary); }
.comment-admin .comment-author { color: var(--primary); }
.comment-client { border-left: 3px solid var(--border); }

/* comment list (admin table) */
.admin-comments { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.admin-comments li { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .55rem; }
.admin-comments .comment-author { margin-bottom: .15rem; }
.admin-comments .comment-time { margin-top: .2rem; }
.reply-form { display: flex; gap: .5rem; align-items: flex-start; }
.reply-form textarea {
    flex: 1; padding: .5rem .6rem; border-radius: 8px; resize: vertical; min-height: 2.4rem;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}

/* Edge tab that opens/closes the drawer; rides the drawer edge when open. */
.drawer-toggle {
    position: absolute; top: 1rem; right: 0; z-index: 5;
    display: flex; align-items: center; gap: .45rem;
    background: var(--primary); color: var(--primary-ink); border: 0;
    border-radius: 10px 0 0 10px;
    padding: .6rem .85rem; font: inherit; font-weight: 600; cursor: pointer;
    box-shadow: var(--shadow);
    transition: right .25s ease;
}
.viewer.drawer-open .drawer-toggle { right: var(--drawer-w); }
.drawer-chevron { font-size: 1.2rem; line-height: 1; transition: transform .25s ease; }
.viewer.drawer-open .drawer-chevron { transform: rotate(180deg); }

/* Avoid the open/close animation firing on initial page load. */
.viewer.no-anim .viewer-side,
.viewer.no-anim .drawer-toggle,
.viewer.no-anim .drawer-chevron { transition: none; }

@media (max-width: 480px) {
    .viewer { --drawer-w: 90vw; }
}

/* ---------- admin ---------- */
.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
}
.panel h2 { margin-top: 0; font-size: 1.15rem; }
.row-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }
.row-form input[type=text], .row-form input[type=file] {
    flex: 1 1 200px; padding: .6rem .8rem; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}
.row-actions { display: flex; gap: .5rem; align-items: center; }
.danger-zone { border-color: rgba(255, 107, 107, .35); }
.table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.table th, .table td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.flash {
    background: rgba(91, 140, 255, .12); border: 1px solid rgba(91, 140, 255, .35);
    color: #cdd9ff; padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1.25rem;
}
.pin-reveal { font-size: 1.1rem; letter-spacing: .15em; background: #0c0e12; padding: .15rem .5rem; border-radius: 6px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- confirmation modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 50;
    display: grid; place-items: center; padding: 1.5rem;
    background: rgba(6, 8, 12, .62);
    opacity: 0; transition: opacity .18s ease;
}
.modal-overlay.show { opacity: 1; }
.modal-dialog {
    width: 100%; max-width: 420px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.5rem 1.5rem 1.25rem;
    transform: translateY(10px) scale(.98);
    transition: transform .18s ease;
}
.modal-overlay.show .modal-dialog { transform: none; }
.modal-title { margin: 0 0 .5rem; font-size: 1.25rem; }
.modal-message { margin: 0 0 1.4rem; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }
@media (prefers-reduced-motion: reduce) {
    .modal-overlay, .modal-dialog { transition: none; }
}
