/* App Builder — design system, ported from the Stitch-generated design
   (project "App Builder Admin Panel"). Colors/typography/spacing below are
   the exact tokens from that design's DESIGN.md, reimplemented on top of
   Bootstrap 5 (the source used Tailwind CDN; this app deliberately uses
   Bootstrap per the "no framework, plain PHP, Bootstrap 5" requirement). */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap');

:root {
    /* --- Design system color tokens (light mode) --- */
    --ds-primary: #3525cd;
    --ds-on-primary: #ffffff;
    --ds-primary-container: #4f46e5;
    --ds-on-primary-container: #dad7ff;
    --ds-primary-fixed: #e2dfff;
    --ds-primary-fixed-dim: #c3c0ff;

    --ds-secondary: #505f76;
    --ds-on-secondary: #ffffff;
    --ds-secondary-container: #d0e1fb;
    --ds-on-secondary-container: #54647a;

    --ds-tertiary: #7e3000;
    --ds-on-tertiary: #ffffff;
    --ds-tertiary-container: #a44100;
    --ds-on-tertiary-container: #ffd2be;

    --ds-error: #ba1a1a;
    --ds-on-error: #ffffff;
    --ds-error-container: #ffdad6;
    --ds-on-error-container: #93000a;

    --ds-background: #fcf8ff;
    --ds-on-background: #1b1b24;
    --ds-surface: #fcf8ff;
    --ds-on-surface: #1b1b24;
    --ds-on-surface-variant: #464555;
    --ds-outline: #777587;
    --ds-outline-variant: #c7c4d8;

    --ds-surface-container-lowest: #ffffff;
    --ds-surface-container-low: #f5f2ff;
    --ds-surface-container: #f0ecf9;
    --ds-surface-container-high: #eae6f4;
    --ds-surface-container-highest: #e4e1ee;
    --ds-surface-variant: #e4e1ee;
    --ds-surface-dim: #dcd8e5;
    --ds-surface-bright: #fcf8ff;
    --ds-surface-tint: #4d44e3;

    --ds-inverse-surface: #302f39;
    --ds-inverse-on-surface: #f3effc;
    --ds-inverse-primary: #c3c0ff;

    /* Semantic status colors (from Stitch component guidance) */
    --ds-success-bg: #e6f4ea;
    --ds-success-fg: #137333;
    --ds-warning-bg: #fef7e0;
    --ds-warning-fg: #b06000;
    --ds-warning-dot: #ea8600;
    --ds-danger-bg: #fce8e6;
    --ds-danger-fg: #c5221f;

    /* Typography */
    --ds-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Spacing (4px base) */
    --ds-space-xs: 4px;
    --ds-space-sm: 8px;
    --ds-space-md: 16px;
    --ds-space-lg: 24px;
    --ds-space-xl: 32px;
    --ds-space-2xl: 48px;
    --ds-space-3xl: 64px;
    --ds-container-max: 1280px;
    --ds-sidebar-width: 288px; /* Tailwind w-72 */

    /* Radius */
    --ds-radius-sm: 0.25rem;
    --ds-radius: 0.5rem;
    --ds-radius-lg: 0.75rem;
    --ds-radius-xl: 1rem;
    --ds-radius-2xl: 1.5rem;
    --ds-radius-full: 9999px;

    /* Bootstrap overrides so stock components (buttons, badges, forms) pick up the palette */
    --bs-primary: var(--ds-primary);
    --bs-primary-rgb: 53, 37, 205;
    --bs-body-font-family: var(--ds-font);
    --bs-body-bg: var(--ds-background);
    --bs-body-color: var(--ds-on-surface);
    --bs-border-radius: var(--ds-radius);
    --bs-border-radius-lg: var(--ds-radius-lg);
    --bs-link-color: var(--ds-primary);
    --bs-link-hover-color: var(--ds-primary-container);
}

body {
    font-family: var(--ds-font);
    background: var(--ds-background);
    color: var(--ds-on-surface);
}

.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
    font-size: 20px;
    line-height: 1;
    vertical-align: middle;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

.btn-primary {
    background-color: var(--ds-primary);
    border-color: var(--ds-primary);
    color: var(--ds-on-primary);
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--ds-primary-container);
    border-color: var(--ds-primary-container);
    color: var(--ds-on-primary);
}
.btn-outline-secondary {
    background: var(--ds-surface-container);
    border: none;
    color: var(--ds-on-surface-variant);
}
.btn-outline-secondary:hover {
    background: var(--ds-surface-container-high);
    color: var(--ds-on-surface);
}
.btn-danger-soft {
    background: var(--ds-surface-container);
    color: var(--ds-error);
    border: none;
}
.btn-danger-soft:hover { background: var(--ds-error-container); color: var(--ds-on-error-container); }

.text-primary { color: var(--ds-primary) !important; }
.text-muted-ds { color: var(--ds-on-surface-variant) !important; }

/* --- App shell --- */
.app-sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--ds-sidebar-width);
    background: var(--ds-surface-container);
    border-right: 1px solid rgba(199, 196, 216, .3);
    z-index: 1030;
    display: flex;
    flex-direction: column;
}
.app-sidebar .sidebar-brand {
    height: 64px;
    display: flex;
    align-items: center;
    gap: var(--ds-space-sm);
    padding: 0 var(--ds-space-lg);
    margin-bottom: var(--ds-space-lg);
}
.app-sidebar .sidebar-brand img { height: 32px; width: auto; }
.app-sidebar .sidebar-brand span {
    font-size: 24px; font-weight: 600; color: var(--ds-primary); letter-spacing: -0.01em;
}
.app-sidebar nav { flex: 1; padding: 0 var(--ds-space-md); display: flex; flex-direction: column; gap: 4px; }
.app-sidebar .nav-link {
    display: flex; align-items: center; gap: var(--ds-space-md);
    padding: var(--ds-space-sm) var(--ds-space-md);
    border-radius: var(--ds-radius);
    color: var(--ds-on-surface-variant);
    font-weight: 500; font-size: 14px;
    transition: all .2s ease;
}
.app-sidebar .nav-link:hover { background: var(--ds-surface-container-high); color: var(--ds-on-surface); }
.app-sidebar .nav-link.active { background: var(--ds-primary-container); color: var(--ds-on-primary-container); }
.app-sidebar .sidebar-user {
    margin: var(--ds-space-lg);
    padding: var(--ds-space-sm);
    border-radius: var(--ds-radius-xl);
    background: var(--ds-surface-container-high);
    display: flex; align-items: center; gap: var(--ds-space-md);
}

.app-main { margin-left: var(--ds-sidebar-width); display: flex; flex-direction: column; min-height: 100vh; }
.app-topbar {
    position: sticky; top: 0; z-index: 1020;
    height: 64px;
    background: rgba(252, 248, 255, .85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(199, 196, 216, .2);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--ds-space-xl);
}
.app-content {
    flex: 1;
    width: 100%;
    max-width: var(--ds-container-max);
    margin: 0 auto;
    padding: var(--ds-space-xl);
}

.avatar-circle {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--ds-primary); color: var(--ds-on-primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
}

/* Mobile: collapse sidebar, use offcanvas */
@media (max-width: 991.98px) {
    .app-sidebar { display: none; }
    .app-main { margin-left: 0; }
    .app-content { padding: var(--ds-space-md); }
}

/* --- Cards / stat tiles --- */
.ds-card {
    background: var(--ds-surface-container);
    border-radius: var(--ds-radius-xl);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.ds-card-lowest {
    background: var(--ds-surface-container-lowest);
    border-radius: var(--ds-radius-xl);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-tile {
    background: var(--ds-surface-container);
    border-radius: var(--ds-radius-xl);
    padding: var(--ds-space-md);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-tile .stat-label { font-size: 14px; font-weight: 500; color: var(--ds-on-surface-variant); }
.stat-tile .stat-value { font-size: 30px; font-weight: 600; color: var(--ds-on-surface); line-height: 1.2; }
.stat-tile .stat-delta { font-size: 12px; font-weight: 600; color: var(--ds-surface-tint); }

/* --- Status badges --- */
.badge-status {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 10px;
    border-radius: var(--ds-radius-full);
    font-size: 12px; font-weight: 600;
}
.badge-status.status-success { background: var(--ds-success-bg); color: var(--ds-success-fg); }
.badge-status.status-building,
.badge-status.status-queued { background: var(--ds-warning-bg); color: var(--ds-warning-fg); }
.badge-status.status-building .status-dot,
.badge-status.status-queued .status-dot { background: var(--ds-warning-dot); animation: ds-pulse 1.5s ease-in-out infinite; }
.badge-status.status-failed,
.badge-status.status-error { background: var(--ds-danger-bg); color: var(--ds-danger-fg); }
.badge-status .status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
@keyframes ds-pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* --- Tables --- */
.ds-table { width: 100%; text-align: left; }
.ds-table thead { background: var(--ds-surface-container-low); color: var(--ds-on-surface-variant); }
.ds-table th { padding: var(--ds-space-md) var(--ds-space-lg); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.ds-table td { padding: var(--ds-space-sm) var(--ds-space-lg); vertical-align: middle; }
.ds-table tbody tr { border-top: 1px solid rgba(199,196,216,.2); }
.ds-table tbody tr:hover { background: var(--ds-surface-container-low); }

/* --- Forms --- */
.ds-input {
    width: 100%;
    background: var(--ds-surface);
    border: none;
    border-radius: var(--ds-radius);
    height: 38px;
    padding: 0 var(--ds-space-sm);
    font-family: var(--ds-font);
    font-size: 16px;
    color: var(--ds-on-surface);
    box-shadow: inset 0 1px 2px rgba(0,0,0,.05);
}
.ds-input:focus { outline: none; box-shadow: 0 0 0 2px var(--ds-primary); }
.ds-label { font-size: 14px; font-weight: 500; color: var(--ds-on-surface); margin-bottom: 4px; display: block; }
.ds-help { font-size: 13px; color: var(--ds-on-surface-variant); }

/* --- Upload dropzones --- */
.upload-dropzone {
    position: relative;
    height: 192px;
    background: var(--ds-surface-container);
    border: 2px dashed rgba(119,117,135,.3);
    border-radius: var(--ds-radius-xl);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--ds-space-md);
    text-align: center;
    cursor: pointer;
    transition: all .2s ease;
}
.upload-dropzone:hover { border-color: var(--ds-primary); background: rgba(53,37,205,.05); }
.upload-dropzone .upload-icon-circle {
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--ds-surface-container-high);
    display: flex; align-items: center; justify-content: center;
    color: var(--ds-on-surface-variant);
}
.upload-dropzone img.preview { max-height: 100%; max-width: 100%; object-fit: contain; border-radius: var(--ds-radius); }

/* --- Login screen --- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ds-background); position: relative; overflow: hidden; }
.login-glow { position: absolute; width: 800px; height: 800px; border-radius: 50%; background: rgba(226,223,255,.35); filter: blur(100px); }
.login-card { position: relative; z-index: 1; width: 100%; max-width: 420px; background: var(--ds-surface-container-lowest); border-radius: var(--ds-radius-xl); box-shadow: 0 10px 30px rgba(0,0,0,.08); padding: 40px; }

/* --- Phone mockup live preview (school form) --- */
.brand-preview-wrap {
    background: var(--ds-surface-container-high);
    border-radius: var(--ds-radius-xl);
    padding: var(--ds-space-lg);
    display: flex; align-items: center; justify-content: center;
    min-height: 600px;
    position: relative;
    overflow: hidden;
}
.brand-preview-phone {
    position: relative;
    width: 260px; height: 540px;
    border-radius: 36px;
    border: 6px solid var(--ds-surface-container-lowest);
    box-shadow: 0 20px 40px rgba(0,0,0,.15);
    overflow: hidden;
    transition: background-color .3s ease;
}
.brand-preview-phone .blob { position: absolute; border-radius: 50%; filter: blur(30px); opacity: .4; transition: background-color .3s ease; }
.brand-preview-phone .blob-1 { width: 128px; height: 128px; top: -40px; right: -40px; }
.brand-preview-phone .blob-2 { width: 160px; height: 160px; bottom: 40px; left: -40px; }
.brand-preview-phone .content { position: absolute; inset: 0; display: flex; flex-direction: column; padding: var(--ds-space-lg); z-index: 1; }
.brand-preview-phone .logo-circle {
    width: 88px; height: 88px; border-radius: var(--ds-radius-xl); margin: 0 auto;
    display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 10px rgba(0,0,0,.15);
    transition: background-color .3s ease;
}
.brand-preview-phone .logo-circle img { max-width: 60%; max-height: 60%; object-fit: contain; }
.brand-preview-phone .btn-preview { height: 44px; border-radius: var(--ds-radius); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 500; font-size: 14px; transition: background-color .3s ease; }
.live-badge {
    position: absolute; top: var(--ds-space-sm); right: var(--ds-space-sm);
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: var(--ds-radius-full);
    background: rgba(252,248,255,.85); font-size: 12px; font-weight: 600; color: var(--ds-on-surface);
    box-shadow: 0 1px 3px rgba(0,0,0,.1); z-index: 2;
}
.live-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ds-primary); position: relative; }

/* --- Sticky bottom action bar --- */
/* The form needs enough bottom padding that its last real section can
   scroll fully clear of the sticky bar rather than being covered by it. */
#school-form { padding-bottom: 96px; }

.form-action-bar {
    position: sticky; bottom: 0;
    background: rgba(252,248,255,.95);
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(199,196,216,.3);
    padding: var(--ds-space-lg);
    display: flex; justify-content: flex-end; gap: var(--ds-space-md);
    margin: 0 calc(var(--ds-space-xl) * -1) calc(var(--ds-space-xl) * -1);
}

/* --- Build timeline --- */
.build-timeline { position: relative; padding-left: 8px; margin-left: 8px; }
.build-timeline::before {
    content: ''; position: absolute; left: 8px; top: 8px; bottom: 24px; width: 2px; background: var(--ds-surface-container-highest);
}
.build-timeline .step { position: relative; padding-left: var(--ds-space-lg); padding-bottom: var(--ds-space-lg); }
.build-timeline .step .dot {
    position: absolute; left: -1px; top: 4px; width: 20px; height: 20px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--ds-surface-container-highest); color: var(--ds-on-surface-variant);
}
.build-timeline .step.done .dot { background: var(--ds-primary); color: #fff; }
.build-timeline .step.active .dot { background: var(--ds-primary); color: #fff; box-shadow: 0 0 0 4px rgba(53,37,205,.2); }
.build-timeline .step h6 { margin: 0; font-size: 15px; font-weight: 600; color: var(--ds-on-surface); }
.build-timeline .step.active h6 { color: var(--ds-primary); }
.build-timeline .step p { margin: 2px 0 0; font-size: 12px; color: var(--ds-on-surface-variant); }

/* --- Terminal / log viewer --- */
.log-terminal {
    background: var(--ds-inverse-surface);
    color: rgba(243,239,252,.9);
    border-radius: var(--ds-radius-xl);
    overflow: hidden;
}
.log-terminal .log-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--ds-space-sm) var(--ds-space-md);
    background: rgba(27,27,36,.2);
    border-bottom: 1px solid rgba(27,27,36,.3);
}
.log-terminal pre {
    margin: 0; padding: var(--ds-space-md);
    font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
    font-size: 13px; line-height: 1.7;
    max-height: 420px; overflow-y: auto;
    white-space: pre-wrap; word-break: break-word;
}

/* --- Env var table (monospace) --- */
.env-table { width: 100%; font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 13px; }
.env-table td { padding: var(--ds-space-sm) var(--ds-space-md); border-bottom: 1px solid var(--ds-surface-container-highest); }
.env-table td:first-child { color: var(--ds-on-surface-variant); width: 33%; }
