/* ==========================================================
   Spillcraft WC → iQ Sync — Portal styles
   Brand vars match Spill360 (same Spillcraft house style).
   ========================================================== */

:root {
    --brand-orange:        #F05a24;
    --brand-orange-hover:  #d1491b;
    --brand-orange-soft:   rgba(240, 90, 36, 0.10);
    --brand-dark:          #1e293b;
    --brand-gray-dark:     #404040;
    --brand-gray-med:      #595959;
    --bg-light:            #f8fafc;
    --bg-white:            #ffffff;
    --border-light:        #e2e8f0;
    --text-muted:          #64748b;
    --success:             #10b981;
    --danger:              #ef4444;
    --warning:             #f59e0b;
    --info:                #3b82f6;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', -apple-system, sans-serif; }

html, body { height: 100%; }
body {
    background-color: var(--bg-light);
    color: var(--brand-dark);
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    line-height: 1.5;
}

.screen { display: none; }
.screen.active { display: flex; }

/* ---------- LOGIN ---------- */
#login-screen {
    height: 100vh;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-light);
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 20px 20px;
}
.login-card {
    background: var(--bg-white);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    border: 1px solid var(--border-light);
}
.login-card .logo { max-width: 200px; margin-bottom: 28px; }
.login-card h2 { margin-bottom: 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.4px; color: var(--brand-dark); }
.login-card p { margin-bottom: 26px; color: var(--text-muted); font-size: 14px; }
.login-card .hint { font-size: 12px; color: var(--text-muted); margin-top: 14px; margin-bottom: 0; }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--brand-gray-med); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--brand-orange);
    box-shadow: 0 0 0 3px var(--brand-orange-soft);
}
.form-group input[readonly] { background: #f1f5f9; color: var(--text-muted); }

.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 14px; font-weight: 600; min-height: 18px; }
.error-msg:empty { margin-bottom: 0; min-height: 0; }

/* ---------- BUTTONS ---------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--brand-orange); color: white; width: 100%; }
.btn-primary:hover { background: var(--brand-orange-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }

.btn-secondary { background: var(--bg-white); color: var(--brand-dark); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: #f1f5f9; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--brand-dark); background: #f1f5f9; }

.btn-inline { padding: 6px 12px; font-size: 12px; }

/* ---------- LAYOUT ---------- */
.layout { height: 100vh; width: 100vw; overflow: hidden; }

.sidebar {
    width: 250px;
    background-color: var(--brand-gray-dark);
    display: flex;
    flex-direction: column;
    color: var(--bg-white);
    flex-shrink: 0;
}
.sidebar-header {
    padding: 24px;
    background-color: rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sidebar-header img { max-width: 140px; }

.nav-links { list-style: none; padding: 16px 0; flex: 1; }
.nav-links li {
    padding: 11px 22px;
    cursor: pointer;
    color: #cbd5e1;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-links li i { font-size: 17px; opacity: 0.7; }
.nav-links li:hover { background-color: rgba(255,255,255,0.05); color: var(--bg-white); }
.nav-links li.active {
    background-color: var(--brand-orange-soft);
    color: var(--brand-orange);
    border-left-color: var(--brand-orange);
}
.nav-links li.active i { opacity: 1; }

.sidebar-footer { padding: 16px 22px; border-top: 1px solid rgba(255,255,255,0.05); }
.btn-logout {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #cbd5e1;
    padding: 9px 14px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.1); color: white; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; min-width: 0; }
.topbar {
    background-color: var(--bg-white);
    padding: 18px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar h1 { font-size: 20px; font-weight: 600; color: var(--brand-dark); letter-spacing: -0.4px; }
.topbar-meta { display: flex; gap: 10px; align-items: center; }

.content-area { padding: 28px 30px; max-width: 1400px; width: 100%; margin: 0 auto; flex: 1; }

/* ---------- CARDS / PANELS ---------- */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.card + .card { margin-top: 18px; }
.card h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; color: var(--brand-dark); }
.card h2 + p { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
    gap: 16px;
    flex-wrap: wrap;
}
.card-header > div:first-child { flex: 1; min-width: 0; }
.card-header h2 { margin-bottom: 4px; }
.card-header p { color: var(--text-muted); font-size: 13px; margin: 0; }

/* ---------- STAT GRID ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 18px;
}
.stat .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 700; color: var(--brand-dark); letter-spacing: -0.5px; }
.stat .value.success { color: var(--success); }
.stat .value.failed  { color: var(--danger); }
.stat .value.pending { color: var(--warning); }
.stat .value.skipped { color: var(--text-muted); }

/* ---------- TABLES ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border-light); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; font-size: 13px; }
th { background: #f8fafc; font-weight: 600; color: var(--brand-gray-med); border-bottom: 1px solid var(--border-light); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr + tr td { border-top: 1px solid var(--border-light); }
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: #f8fafc; }

.tbl-actions { display: flex; gap: 6px; justify-content: flex-end; }

.tbl-empty { padding: 36px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---------- BADGES ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-success { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-failed  { background: rgba(239,68,68,0.12);  color: var(--danger); }
.badge-pending { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-skipped { background: rgba(100,116,139,0.12); color: var(--text-muted); }
.badge-env     { background: rgba(59,130,246,0.12); color: var(--info); }

/* ---------- FORM GRID ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.form-grid .form-group { margin-bottom: 0; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border-light); }
.form-actions .btn-primary { width: auto; padding: 11px 22px; }

/* ---------- EXPANDABLE LOG ROWS ---------- */
.log-detail { background: #f8fafc; padding: 16px 22px; border-top: 1px solid var(--border-light); font-size: 12px; }
.log-detail pre {
    background: var(--brand-dark);
    color: #e2e8f0;
    padding: 14px 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
    font-size: 11.5px;
    line-height: 1.5;
    max-height: 320px;
}
.log-detail .log-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 12px; }
.log-detail .log-meta div { background: white; border: 1px solid var(--border-light); padding: 8px 12px; border-radius: 8px; }
.log-detail .log-meta .lbl { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.log-detail .log-meta .val { font-size: 13px; color: var(--brand-dark); font-family: ui-monospace, monospace; word-break: break-all; }

.log-section-lbl { margin-top: 14px; margin-bottom: 6px; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

.error-banner {
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.25);
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 14px;
    word-break: break-word;
}

.action-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 14px;
}
.action-row .btn-primary, .action-row .btn-secondary, .action-row .btn-ghost {
    width: auto;
}

.payload-edit {
    width: 100%;
    min-height: 240px;
    background: var(--brand-dark);
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 14px 16px;
    font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
    font-size: 12px;
    line-height: 1.55;
    resize: vertical;
    outline: none;
}
.payload-edit:focus { border-color: var(--brand-orange); box-shadow: 0 0 0 3px var(--brand-orange-soft); }

/* ---------- TOAST ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--brand-dark);
    color: white;
    padding: 13px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 12px 28px rgba(0,0,0,0.18);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 1000;
    max-width: 380px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- SANDBOX BANNER ---------- */
.sandbox-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--warning);
    color: var(--brand-dark);
    text-align: center;
    padding: 4px 0;
    font: 600 11px/1.4 'Inter', sans-serif;
    letter-spacing: 0.08em;
    z-index: 100000;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    text-transform: uppercase;
}
body.has-sandbox-banner { padding-top: 22px; }

/* ---------- MUTED / HELP TEXT ---------- */
.muted { color: var(--text-muted); font-size: 12px; }
.tag {
    display: inline-block;
    padding: 2px 7px;
    background: #f1f5f9;
    border-radius: 5px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--brand-gray-med);
}
.section-divider { height: 1px; background: var(--border-light); margin: 18px 0; }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 18px; }

/* ---------- LOADING ---------- */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
}
.loading i { font-size: 28px; color: var(--brand-orange); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 768px) {
    .sidebar { width: 64px; }
    .sidebar-header { padding: 16px 8px; }
    .sidebar-header img { max-width: 44px; }
    .nav-links li { padding: 12px; justify-content: center; }
    .nav-links li span, .btn-logout span { display: none; }
    .nav-links li i { font-size: 20px; }
    .content-area { padding: 16px; }
    .topbar { padding: 14px 18px; }
}
