/* MasterForm — admin shell + auth styles
 * Color palette lifted from the original GAS Master Form:
 *   #FF9E1B (orange / brand accent), #1B365D (navy / headings),
 *   #4D4D4D (body), #f4f5f7 (page bg).
 * Mobile-first; sidebar collapses below 900px.
 */

:root, html, body {
    color-scheme: only light;       /* fully opt out of browser auto-dark-mode (Chrome/Safari/Edge) */
}
:root {
    --c-orange: #FF9E1B;
    --c-orange-soft: rgba(255, 158, 27, 0.10);
    --c-navy: #1B365D;
    --c-navy-soft: rgba(27, 54, 93, 0.06);
    --c-body: #4D4D4D;
    --c-muted: #888;
    --c-bg: #f4f5f7;
    --c-card: #ffffff;
    --c-border: #e5e7eb;
    --c-border-strong: #d1d5db;
    --c-error-bg: #fdecec;
    --c-error: #b3261e;
    --c-ok-bg: #e6f4ea;
    --c-ok: #137333;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 6px 18px rgba(27, 54, 93, 0.08);
    --r: 10px;
    --pad: 1.25rem;
    --sidebar-w: 240px;
    --topbar-h: 56px;

    --ff: -apple-system, BlinkMacSystemFont, "Segoe UI", Raleway, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--c-bg);
    color: var(--c-body);
    font: 15px/1.55 var(--ff);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--c-navy); text-decoration: none; }
a:hover { color: var(--c-orange); }

h1, h2, h3 { color: var(--c-navy); margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.125rem; font-weight: 600; }
.muted { color: var(--c-muted); }
code { background: var(--c-bg); border: 1px solid var(--c-border); padding: 0 .3rem; border-radius: 4px; font-size: .85em; }
pre { background: var(--c-bg); border: 1px solid var(--c-border); padding: .75rem; border-radius: 6px; font-size: .85rem; overflow: auto; }

/* ======== Auth (login) ======== */

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: var(--c-bg); }
.auth-shell { width: 100%; max-width: 420px; }
.auth-card { background: var(--c-card); border: 1px solid var(--c-border); border-radius: 14px; padding: 2rem 1.75rem; box-shadow: var(--shadow-md); }
.auth-brand {
    display: flex; align-items: center; justify-content: center;
    gap: .75rem;
    margin-bottom: 1.75rem;
}
.auth-brand-icon {
    width: 44px; height: 44px;
    object-fit: contain;
    border-radius: 10px;
    background: #fff;
    padding: 2px;
}
.auth-brand h1 { margin: 0; font-size: 1.35rem; color: var(--c-navy); }

/* Login: placeholder-only inputs (no visible labels) */
.auth-card .input {
    width: 100%;
    padding: .75rem .9rem;
    margin-bottom: .8rem;
    border: 1px solid var(--c-border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--c-body);
    font: inherit;
    transition: border-color .12s, box-shadow .12s;
}
.auth-card .input:focus {
    outline: none;
    border-color: var(--c-orange);
    box-shadow: 0 0 0 3px var(--c-orange-soft);
}
.auth-card .btn-block { margin-top: .35rem; }
.auth-footer { text-align: center; color: var(--c-muted); font-size: .8rem; margin-top: 1rem; }
.auth-footer a { color: var(--c-muted); }

/* ======== Forms ======== */

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-size: .8125rem; font-weight: 500; color: var(--c-navy); margin-bottom: .35rem; }
.field input, .field textarea, .field select {
    width: 100%;
    padding: .65rem .8rem;
    border: 1px solid var(--c-border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--c-body);
    font: inherit;
    transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none;
    border-color: var(--c-orange);
    box-shadow: 0 0 0 3px var(--c-orange-soft);
}

/* Leading-icon wrapper. Wrap an input/select-wrap in <div class="input-wrap with-icon">
   along with <i data-lucide="..." class="field-icon"></i> at top to surface what
   the field is even when pre-filled (placeholder gets hidden once the input has a value). */
.input-wrap { position: relative; display: block; }
.input-wrap.with-icon > .field-icon {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--c-muted);
    pointer-events: none;
    z-index: 1;
}
.input-wrap.with-icon > .input,
.input-wrap.with-icon > .select-wrap > .input {
    padding-left: 2.4rem;
}
/* Custom select chevron — required, otherwise the inline material-icons span
   falls beneath the <select> as a stray "v" character. */
.select-wrap { position: relative; display: block; }
.select-wrap > .input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 2.4rem;
    cursor: pointer;
}
.select-wrap > .material-icons-outlined {
    position: absolute;
    right: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--c-muted);
    font-size: 20px;
    line-height: 1;
    pointer-events: none;
}
/* Textareas: pin icon to top instead of vertically centered. */
.input-wrap.with-icon.textarea > .field-icon {
    top: 1.05rem;
    transform: none;
}
.input-wrap.with-icon > textarea.input { padding-left: 2.4rem; }

/* Help text shown BELOW an input (when label-above is dropped in favour of
   placeholder-inside). Use .field-help for the small muted line. */
.field-help {
    display: block;
    margin-top: .35rem;
    font-size: .75rem;
    color: var(--c-muted);
    line-height: 1.4;
}
.field-help code { font-size: .9em; }

/* Standalone .input — used outside <label class="field"> wrappers,
   e.g. in .inline-form rows. Same look as .field input. */
input.input, textarea.input, select.input {
    padding: .65rem .8rem;
    border: 1px solid var(--c-border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--c-body);
    font: inherit;
    transition: border-color .12s, box-shadow .12s;
}
input.input:focus, textarea.input:focus, select.input:focus {
    outline: none;
    border-color: var(--c-orange);
    box-shadow: 0 0 0 3px var(--c-orange-soft);
}

/* Inline form row — placeholder-only inputs in a single row on desktop,
   wrap to multi-row on narrow screens. Use this for short admin forms
   (Add user, Add tag, etc.) where labels above each field would be noise. */
.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    align-items: stretch;
    margin-top: .25rem;
}
.inline-form > .input,
.inline-form > .input-wrap { flex: 1 1 200px; min-width: 0; width: auto; }
.inline-form > .btn        { flex: 0 0 auto; align-self: stretch; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .65rem 1.1rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    background: #fff;
    color: var(--c-navy);
    border-color: var(--c-border-strong);
    transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { border-color: var(--c-navy); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-orange); color: #fff; border-color: var(--c-orange); }
.btn-primary:hover { background: #e88a0a; border-color: #e88a0a; color: #fff; }
.btn-secondary { background: var(--c-card); color: var(--c-navy); }
.btn-danger  { background: #fff; color: var(--c-error); border-color: rgba(220,38,38,.3); }
.btn-danger:hover { background: var(--c-error-bg); border-color: var(--c-error); color: var(--c-error); }
.btn-success { background: #fff; color: var(--c-ok); border-color: rgba(19,115,51,.3); }
.btn-success:hover { background: var(--c-ok-bg); border-color: var(--c-ok); color: var(--c-ok); }
.btn-block { display: flex; width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn .icon-lucide,
.btn i[data-lucide] { width: 16px; height: 16px; }
.btn-sm { padding: .4rem .65rem; font-size: .8125rem; gap: .3rem; }
.btn-icon { padding: .4rem; gap: 0; }      /* square icon-only button */
.btn-icon i[data-lucide] { width: 18px; height: 18px; }
/* Inline icon button used in tables */
.row-action {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    color: var(--c-navy);
    background: transparent;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
.row-action i[data-lucide] { width: 18px; height: 18px; }
.row-action:hover { background: var(--c-bg); border-color: var(--c-border); color: var(--c-orange); }
.row-action.danger:hover { color: var(--c-error); border-color: rgba(220,38,38,.3); background: var(--c-error-bg); }
.row-action.success:hover { color: var(--c-ok); border-color: rgba(19,115,51,.3); background: var(--c-ok-bg); }
.row-action-group { display: inline-flex; gap: .25rem; }

/* ======== Alerts ======== */

.alert { padding: .65rem .85rem; border-radius: 8px; font-size: .9rem; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-error { background: var(--c-error-bg); border-color: rgba(179,38,30,.2); color: var(--c-error); }
.alert-ok    { background: var(--c-ok-bg); border-color: rgba(19,115,51,.2); color: var(--c-ok); }

/* ======== Unified site nav (shared with public pages) ======== */

.nav {
    background: var(--c-navy);
    padding: 10px 32px;
    display: flex; align-items: center; justify-content: center;
    position: sticky; top: 0; z-index: 100;
    min-height: var(--topbar-h);
}
.nav-logo {
    display: inline-flex; align-items: center; gap: 12px;
    color: #fff; text-decoration: none;
    font-family: var(--ff);
}
.nav-logo:hover { opacity: .85; color: #fff; }
.nav-logo img { height: 36px; object-fit: contain; }
.nav-logo span { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .01em; }

.nav-burger {
    position: absolute; left: 16px;
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
    color: #fff; cursor: pointer;
    width: 36px; height: 36px;
    border-radius: 8px;
    display: none; align-items: center; justify-content: center;
    font-family: 'Material Icons Outlined';
}
.nav-burger:hover { background: rgba(255,255,255,0.18); }
.nav-burger .icon { font-family: 'Material Icons Outlined'; font-size: 22px; color: #fff; font-style: normal; }

.nav-right { position: absolute; right: 24px; display: inline-flex; align-items: center; gap: 12px; }

.nav-signin {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    color: #fff; text-decoration: none;
    transition: background .15s, border-color .15s;
}
.nav-signin:hover { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.25); color: #fff; }
.nav-signin .icon { font-family: 'Material Icons Outlined'; font-size: 20px; color: rgba(255,255,255,.85); font-style: normal; }

.nav-user { position: relative; }
.nav-user > summary {
    list-style: none; cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: #fff;
    font-family: var(--ff);
    font-size: 13px; font-weight: 600;
    transition: background .15s;
}
.nav-user > summary::-webkit-details-marker,
.nav-user > summary::marker { display: none; }
.nav-user > summary:hover { background: rgba(255,255,255,0.18); }
.nav-user > summary .icon { font-family: 'Material Icons Outlined'; font-size: 18px; color: rgba(255,255,255,.7); font-style: normal; }
.nav-user-name { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-panel {
    position: absolute; right: 0; top: calc(100% + 6px);
    background: #fff;
    border: 1px solid var(--c-border);
    border-radius: 10px;
    min-width: 200px;
    padding: 4px;
    box-shadow: 0 10px 28px rgba(27,54,93,.18);
    z-index: 110;
}
.nav-user-panel a {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    color: var(--c-body); text-decoration: none;
    font-size: 13px;
    border-radius: 6px;
}
.nav-user-panel a:hover { background: var(--c-bg); color: var(--c-navy); }
.nav-user-panel a .icon { font-family: 'Material Icons Outlined'; font-size: 18px; color: var(--c-muted); font-style: normal; }

@media (max-width: 540px) {
    .nav { padding: 10px 16px; }
    .nav-logo img { height: 28px; }
    .nav-logo span { font-size: 14px; }
    .nav-right { right: 12px; }
    .nav-burger { left: 12px; width: 32px; height: 32px; }
    .nav-burger .icon { font-size: 20px; }
    .nav-signin { width: 32px; height: 32px; }
    .nav-signin .icon { font-size: 18px; }
    .nav-user > summary { padding: 4px 8px; font-size: 12px; }
    .nav-user-name { max-width: 100px; }
}

.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: #fff;
    border-right: 1px solid var(--c-border);
    display: flex; flex-direction: column;
    position: sticky; top: var(--topbar-h);
    align-self: flex-start;
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
}
.sidebar-nav { padding: .75rem .5rem; flex: 1; }
.sidebar-link {
    display: flex; align-items: center; gap: .65rem;
    padding: .55rem .75rem;
    border-radius: 7px;
    color: var(--c-body);
    font-size: .9rem;
    margin-bottom: 2px;
    position: relative;
}
.sidebar-link i[data-lucide] { width: 18px; height: 18px; }
.sidebar-link:hover { background: var(--c-bg); color: var(--c-navy); }
.sidebar-link.is-active {
    background: var(--c-orange-soft);
    color: var(--c-navy);
    font-weight: 600;
}
.sidebar-link.is-active::before {
    content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
    width: 3px; background: var(--c-orange); border-radius: 0 3px 3px 0;
}
.phase-pill {
    margin-left: auto;
    background: var(--c-navy-soft); color: var(--c-navy);
    font-size: .65rem; font-weight: 600;
    padding: 1px 6px; border-radius: 10px;
    letter-spacing: .02em;
}
.sidebar-footer {
    padding: .75rem 1rem;
    border-top: 1px solid var(--c-border);
    color: var(--c-muted);
    font-size: .75rem;
}

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 25;
}

.main {
    flex: 1; min-width: 0;
    padding: 1.75rem;
}
.page-head { margin-bottom: .9rem; }
.page-head h1 { margin-bottom: .1rem; line-height: 1.15; }
.page-head p,
.page-head .muted { margin: 0; font-size: .8rem; line-height: 1.45; }

/* ======== Cards / data ======== */

.card {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--r);
    padding: var(--pad);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}
.card h2 { margin-top: 0; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .75rem; margin: 0; }
.kv dt { color: var(--c-muted); font-size: .85rem; }
.kv dd { margin: 0; }

.kv-table { width: 100%; border-collapse: collapse; }
.kv-table th, .kv-table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--c-border); font-size: .9rem; }
.kv-table th { color: var(--c-muted); font-weight: 500; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }

.api-key {
    word-break: break-all;
    font-size: .85rem;
}

/* Compact filter row used by contacts / submissions admin lists.
   Leading icon inside each input/select; no text labels above; icon-only
   Filter + Clear buttons. Aim: tight vertical footprint + clear meaning. */
.filter-row {
    display: flex; flex-wrap: wrap; gap: .5rem; align-items: stretch;
    padding: .55rem .65rem;
    margin-bottom: 1rem;
}
.filter-row > .filter-search,
.filter-row > .filter-pick {
    position: relative;
    flex: 1 1 160px; min-width: 140px;
}
.filter-row > .filter-search { flex: 2 1 220px; }      /* search gets more room */
.filter-row > .filter-search input,
.filter-row > .filter-pick select {
    width: 100%;
    height: 38px;
    padding: 0 32px 0 36px;          /* leading icon + trailing arrow */
    border: 1px solid var(--c-border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--c-body);
    font: inherit;
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
}
.filter-row > .filter-search input:focus,
.filter-row > .filter-pick select:focus {
    outline: none;
    border-color: var(--c-orange);
    box-shadow: 0 0 0 3px var(--c-orange-soft);
}
.filter-row .filter-icon {
    position: absolute;
    left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--c-muted);
    pointer-events: none;
    width: 16px !important; height: 16px !important;
}
.filter-row .filter-arrow {
    position: absolute;
    right: 10px; top: 50%; transform: translateY(-50%);
    color: var(--c-muted);
    pointer-events: none;
    width: 16px !important; height: 16px !important;
}
.filter-row .filter-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.filter-row .filter-actions .btn {
    width: 38px; height: 38px;
    padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
}
.filter-row .filter-actions .btn i[data-lucide] { width: 16px; height: 16px; }

/* Country / region flag display (shared admin + public) */
.region-flag {
    display: inline-block;
    vertical-align: -2px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
}
.region-flag-other { font-size: 14px; }
.region-display {
    display: inline-flex; align-items: center; gap: .4rem;
    white-space: nowrap;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    display: grid; grid-template-columns: auto 1fr;
    align-items: center; column-gap: .85rem;
    padding: 1rem;
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--r);
    text-decoration: none;
    color: var(--c-body);
    box-shadow: var(--shadow-sm);
    transition: border-color .12s, transform .08s;
}
.stat-card:hover { border-color: var(--c-orange); transform: translateY(-1px); }
.stat-card i[data-lucide] { width: 28px; height: 28px; color: var(--c-orange); }
.stat-card strong { display: block; font-size: 1.55rem; color: var(--c-navy); line-height: 1; margin-bottom: .15rem; }
.stat-card span { font-size: .85rem; color: var(--c-muted); }
.stat-card small { grid-column: 2; font-size: .7rem; color: var(--c-muted); }

.stub { text-align: center; padding: 2.5rem 1.5rem; }
.stub-icon { width: 36px; height: 36px; color: var(--c-orange); }
.stub h2 { margin-top: .65rem; }

.phase-list { list-style: none; padding: 0; margin: .75rem 0 0; }
.phase-list li {
    padding: .5rem .25rem;
    display: flex; align-items: center; gap: .65rem;
    border-bottom: 1px dashed var(--c-border);
    font-size: .9rem;
}
.phase-list li:last-child { border-bottom: 0; }

.admin-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--c-border);
    color: var(--c-muted);
    font-size: .8rem;
    text-align: center;
}
.env-tag {
    background: var(--c-navy-soft); color: var(--c-navy);
    padding: 1px 6px; border-radius: 10px;
    font-size: .7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
}

/* Inline status dot — used in lists where a tag column is too noisy.
   Sits to the left of the row name; tooltip carries the status text. */
.status-dot {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-right: .55rem;
    vertical-align: middle;
    background: var(--c-muted);
    box-shadow: 0 0 0 2px transparent;
}
.status-dot--open    { background: var(--c-ok); }
.status-dot--draft   { background: var(--c-muted); }
.status-dot--closed  { background: var(--c-error); }
.status-dot--archived{ background: var(--c-border-strong); }
/* Submission statuses */
.status-dot--pending  { background: var(--c-orange); }
.status-dot--approved { background: var(--c-ok); }
.status-dot--rejected { background: var(--c-error); }

/* ======== Mobile ======== */

@media (max-width: 900px) {
    .nav-burger { display: inline-flex; }
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        height: calc(100vh - var(--topbar-h));
        transform: translateX(-100%);
        transition: transform .2s ease-out;
        z-index: 30;
        box-shadow: var(--shadow-md);
    }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar-overlay.is-open { display: block; }
    .main { padding: 1.25rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .kv { grid-template-columns: 1fr; gap: .15rem; }
    .kv dt { margin-top: .5rem; }
}

@media (max-width: 480px) {
    /* Keep 2 cards per row even on smallest screens — user prefers compact dashboard. */
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: .65rem; }
    .stat-card { padding: .75rem; column-gap: .55rem; }
    .stat-card strong { font-size: 1.25rem; }
    .topbar-brand-text { display: none; }
    .user-email { max-width: 110px; font-size: .8rem; }
}
