:root {
    --purple: #6f42c1;
    --purple-dark: #4f2d8b;
    --purple-soft: #f2ecfb;
    --surface: #ffffff;
    --background: #f5f6fa;
    --text: #202334;
    --muted: #74798c;
    --border: #e5e7ef;
    --success: #15865f;
    --success-soft: #e8f7f1;
    --warning: #bd7410;
    --warning-soft: #fff5df;
    --danger: #c43b4d;
    --danger-soft: #fdecef;
    --info: #2869c7;
    --info-soft: #eaf2ff;
    --shadow: 0 14px 40px rgba(34, 30, 58, .08);
    --radius: 18px;
    --sidebar-width: 270px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--background); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
a { color: var(--purple); text-decoration: none; }
button { cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; background: #24173a; color: #fff; display: flex; flex-direction: column; z-index: 30; }
.brand, .login-brand { display: flex; align-items: center; gap: 12px; }
.brand { padding: 4px 8px 28px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: inline-grid; place-items: center; flex: none; color: #fff; background: linear-gradient(135deg, #9a6de1, #6534b4); box-shadow: 0 10px 25px rgba(126, 75, 204, .35); font-weight: 900; font-size: 20px; }
.brand strong, .login-brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small, .login-brand small { display: block; margin-top: 2px; color: #bcb1cf; font-size: 12px; }
.nav-menu { display: grid; gap: 7px; }
.nav-link { display: flex; align-items: center; gap: 13px; padding: 12px 14px; border-radius: 12px; color: #cfc7dc; font-weight: 650; font-size: 14px; transition: .2s ease; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-link.active { color: #fff; background: linear-gradient(90deg, rgba(145,100,204,.65), rgba(145,100,204,.26)); box-shadow: inset 3px 0 #d7bdf8; }

.nav-submenu .nav-link { padding: 10px 14px; margin-top: 2px; font-weight: 500; }
.nav-submenu .nav-link.active { background: rgba(255,255,255,.1); box-shadow: none; color: #fff; font-weight: 600; }

.nav-icon { width: 24px; height: 24px; display: grid; place-items: center; font-size: 17px; }
.nav-icon-bullet { width: 24px; height: 24px; display: grid; place-items: center; font-size: 14px; opacity: 0.5; }
.nav-group { display: grid; gap: 4px; }
.nav-group-toggle { width: 100%; text-align: left; background: transparent; border: none; font-family: inherit; }
.nav-chevron { margin-left: auto; font-size: 10px; transition: transform 0.2s ease; }
.nav-group.open > .nav-group-toggle .nav-chevron { transform: rotate(180deg); }
.nav-submenu { display: grid; gap: 4px; padding-top: 4px; }
.sidebar-user { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.12); display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; flex: none; border-radius: 50%; background: #9164cc; display: grid; place-items: center; font-weight: 800; }
.sidebar-user-text { min-width: 0; flex: 1; }
.sidebar-user-text strong, .sidebar-user-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-text strong { font-size: 13px; }
.sidebar-user-text small { margin-top: 2px; color: #bcb1cf; font-size: 11px; text-transform: capitalize; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 11px; background: rgba(255,255,255,.08); color: inherit; display: grid; place-items: center; }
.icon-button:hover { background: rgba(255,255,255,.16); }

.main-area { min-width: 0; }
.topbar { min-height: 92px; padding: 20px clamp(20px, 3vw, 42px); display: flex; align-items: center; gap: 15px; background: rgba(245,246,250,.9); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 20; border-bottom: 1px solid rgba(229,231,239,.75); }
.topbar h1 { margin: 0; font-size: clamp(20px, 2vw, 27px); letter-spacing: -.035em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.environment-badge { margin-left: auto; padding: 7px 11px; border-radius: 99px; background: var(--purple-soft); color: var(--purple-dark); text-transform: capitalize; font-size: 11px; font-weight: 800; }
.menu-toggle { display: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); }
.content { padding: 8px clamp(20px, 3vw, 42px) 50px; }

.hero-card { padding: clamp(24px, 4vw, 40px); border-radius: 24px; color: #fff; background: radial-gradient(circle at 85% 15%, rgba(255,255,255,.17), transparent 27%), linear-gradient(125deg, #332049, #7041b4 72%, #9164cc); display: flex; align-items: center; justify-content: space-between; gap: 20px; box-shadow: var(--shadow); }
.hero-card h2 { max-width: 650px; margin: 5px 0 8px; font-size: clamp(25px, 3.4vw, 40px); line-height: 1.08; letter-spacing: -.045em; }
.hero-card p { margin: 0; color: #e8def5; }
.eyebrow { color: #d9c8f2; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; font-size: 11px; }

.stats-grid { margin-top: 22px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 24px rgba(34,30,58,.045); min-width: 0; }
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card span { font-size: 12px; font-weight: 700; }
.stat-card strong { display: block; margin: 7px 0 2px; font-size: 29px; letter-spacing: -.04em; }
.stat-card small { font-size: 11px; }

.panel-grid { margin-top: 22px; display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, .85fr); gap: 20px; align-items: start; }
.panel { margin-top: 22px; padding: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 28px rgba(34,30,58,.05); min-width: 0; }
.panel-grid > .panel { margin-top: 0; }
.panel-header { margin-bottom: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.panel-header h3 { margin: 0; font-size: 17px; letter-spacing: -.025em; }
.panel-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.panel-header > a { font-size: 12px; font-weight: 800; }
.pill, .status-badge { padding: 7px 10px; border-radius: 999px; white-space: nowrap; font-size: 11px; font-weight: 800; }
.pill { background: var(--purple-soft); color: var(--purple-dark); }
.status-badge { color: var(--muted); background: #f0f1f5; }
.status-badge.queued { color: var(--warning); background: var(--warning-soft); }
.status-badge.running { color: var(--info); background: var(--info-soft); }
.status-badge.completed { color: var(--success); background: var(--success-soft); }
.status-badge.failed, .status-badge.error { color: var(--danger); background: var(--danger-soft); }

.button { min-height: 42px; padding: 10px 17px; border: 1px solid transparent; border-radius: 12px; display: inline-flex; justify-content: center; align-items: center; gap: 8px; font-weight: 800; font-size: 13px; transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.button-primary { color: #fff; background: linear-gradient(135deg, #7c4bc4, #5e2fa7); box-shadow: 0 9px 20px rgba(111,66,193,.23); }
.button-success { color: #fff; background: var(--success); }
.button-secondary { color: var(--text); background: #fff; border-color: var(--border); }
.button-danger { color: var(--danger); background: var(--danger-soft); }
.button-block { width: 100%; }
.button-small { min-height: 34px; padding: 7px 11px; font-size: 11px; border-radius: 9px; }

.stack-form { display: grid; gap: 15px; }
.stack-form label { display: grid; gap: 7px; color: #45495a; font-size: 12px; font-weight: 750; }
input, select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #dcdfea; border-radius: 11px; background: #fff; color: var(--text); outline: none; transition: border .15s, box-shadow .15s; }
input:focus, select:focus { border-color: #9c75d1; box-shadow: 0 0 0 4px rgba(145,100,204,.12); }
.alert { margin: 16px 0; padding: 12px 14px; border-radius: 11px; font-size: 12px; line-height: 1.5; }
.alert-error { color: #8e2836; background: var(--danger-soft); border: 1px solid #f3c4cc; }

.login-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at 20% 0%, rgba(145,100,204,.25), transparent 28%), linear-gradient(135deg, #f4f1f9, #ececf4); }
.login-card { width: min(440px, 100%); padding: clamp(28px, 5vw, 42px); border: 1px solid rgba(255,255,255,.75); border-radius: 24px; background: rgba(255,255,255,.94); box-shadow: 0 26px 70px rgba(48,31,75,.16); }
.login-brand { margin-bottom: 30px; }
.login-brand small { color: var(--muted); }
.login-card h1 { margin: 0 0 7px; font-size: 31px; letter-spacing: -.045em; }
.login-card > p { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.login-help { display: block; margin-top: 20px; color: var(--muted); line-height: 1.5; }
.login-help code { overflow-wrap: anywhere; }

.discount-grid { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
.upload-form { display: grid; gap: 14px; }
.dropzone { min-height: 235px; padding: 25px; border: 2px dashed #d7c9e9; border-radius: 16px; background: #fbf9fe; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; transition: .2s ease; }
.dropzone.dragover { border-color: var(--purple); background: var(--purple-soft); }
.dropzone input { display: none; }
.drop-icon { width: 52px; height: 52px; margin-bottom: 13px; border-radius: 16px; background: var(--purple-soft); color: var(--purple); display: grid; place-items: center; font-size: 27px; font-weight: 800; }
.dropzone strong { font-size: 15px; }
.dropzone small { max-width: 300px; margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.selected-file { max-width: 100%; margin-top: 15px; padding: 7px 10px; border-radius: 8px; color: var(--purple-dark); background: #eee7f8; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.process-summary { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.process-summary h4 { margin: 0 0 13px; }
.summary-grid, .metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.summary-grid { margin-bottom: 14px; }
.summary-grid span, .metrics-grid span { padding: 12px; border-radius: 12px; color: var(--muted); background: #f7f7fa; text-align: center; font-size: 10px; }
.summary-grid strong, .metrics-grid strong { display: block; margin-top: 5px; color: var(--text); font-size: 18px; }
.progress-ring-wrap { padding: 8px 0 22px; display: grid; place-items: center; }
.progress-ring { --progress: 0; width: 176px; height: 176px; border-radius: 50%; display: grid; place-items: center; position: relative; background: conic-gradient(var(--purple) calc(var(--progress) * 1%), #ececf2 0); }
.progress-ring::before { content: ""; width: 142px; height: 142px; border-radius: 50%; background: #fff; position: absolute; box-shadow: inset 0 0 0 1px var(--border); }
.progress-ring span { position: relative; z-index: 1; font-size: 28px; font-weight: 900; letter-spacing: -.04em; }
.metrics-grid { grid-template-columns: repeat(4, 1fr); }
.process-meta { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; }
.process-meta code { max-width: 70%; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.logs-console { height: 320px; overflow: auto; padding: 13px; border: 1px solid #303445; border-radius: 13px; background: #1e2130; color: #e7e9f2; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; line-height: 1.55; }
.log-entry { display: grid; grid-template-columns: 64px 72px 1fr; gap: 8px; padding: 7px 6px; border-bottom: 1px solid rgba(255,255,255,.055); }
.log-time { color: #838ba6; }
.log-type { font-weight: 800; text-transform: uppercase; }
.log-entry.info .log-type { color: #8eb8ff; }
.log-entry.success .log-type { color: #71d2aa; }
.log-entry.warning .log-type { color: #f1bd68; }
.log-entry.error .log-type { color: #ff8a9b; }
.log-empty { height: 100%; display: grid; place-items: center; color: #7d849d; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 11px 10px; color: var(--muted); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
td { padding: 13px 10px; border-bottom: 1px solid #f0f1f5; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.filename-cell { max-width: 270px; }
.filename-cell strong, .filename-cell small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filename-cell small { margin-top: 3px; color: var(--muted); }
.table-actions { display: flex; gap: 7px; }
.empty-state { padding: 40px 20px; color: var(--muted); text-align: center; }
.loading-block { color: var(--muted); font-size: 12px; }

.health-list { display: grid; gap: 10px; }
.health-item { padding: 13px; border: 1px solid var(--border); border-radius: 12px; display: flex; align-items: center; gap: 11px; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: #aeb2bd; box-shadow: 0 0 0 4px #f0f1f4; }
.health-item.ok .health-dot { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.health-item.error .health-dot { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.health-item strong, .health-item small { display: block; }
.health-item strong { font-size: 12px; }
.health-item small { margin-top: 3px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.admin-grid { grid-template-columns: minmax(0, .75fr) minmax(0, 1.25fr); }
.admin-list { display: grid; gap: 10px; }
.admin-row { padding: 13px; border: 1px solid var(--border); border-radius: 13px; display: grid; grid-template-columns: 44px minmax(0,1fr) auto; align-items: center; gap: 12px; }
.admin-row .avatar { color: #fff; }
.admin-row strong, .admin-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.role-chip { display: inline-block; margin-top: 5px; padding: 3px 7px; border-radius: 99px; color: var(--purple-dark); background: var(--purple-soft); font-size: 9px; font-weight: 800; text-transform: capitalize; }
.switch-button { min-width: 78px; }
.settings-grid { grid-template-columns: 1fr 1fr; }
.settings-list { margin: 0; display: grid; }
.settings-list > div { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 20px; }
.settings-list > div:last-child { border-bottom: 0; }
.settings-list dt { color: var(--muted); font-size: 12px; }
.settings-list dd { margin: 0; font-size: 12px; font-weight: 800; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.info-grid > div { padding: 16px; border-radius: 13px; background: #f8f8fb; }
.info-grid strong { font-size: 13px; }
.info-grid p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 9px; }
.toast { width: min(360px, calc(100vw - 40px)); padding: 13px 15px; border-radius: 12px; color: #fff; background: #2e3140; box-shadow: var(--shadow); font-size: 12px; animation: toast-in .2s ease; }
.toast.success { background: #166e51; }
.toast.error { background: #9f3040; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .panel-grid, .discount-grid, .admin-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: min(290px, 86vw); transition: transform .22s ease; box-shadow: 22px 0 60px rgba(28,18,43,.28); z-index: 1000; }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: grid; }
    .topbar { min-height: 78px; padding: 14px 18px; }
    .content { padding: 6px 15px 35px; }
    .hero-card { align-items: flex-start; flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 15px; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .panel { padding: 17px; }
    .admin-row { grid-template-columns: 44px 1fr; }
    .admin-row > div:last-child { grid-column: 1 / -1; width: 100%; justify-content: center; }
    .admin-row > div:last-child button { flex: 1; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .environment-badge { display: none; }
    .panel-header { align-items: stretch; flex-direction: column; }
    .summary-grid { grid-template-columns: 1fr; }
    .metrics-grid { grid-template-columns: 1fr; }
    .log-entry { grid-template-columns: 58px 60px 1fr; gap: 5px; font-size: 10px; }
    .settings-list > div { flex-direction: column; gap: 4px; }
    .toast { width: auto; left: 20px; right: 20px; bottom: 20px; }
    .admin-row { grid-template-columns: 1fr; text-align: center; justify-items: center; }
    .admin-row > div:last-child { flex-direction: column; }
    .filename-cell { max-width: 150px; }
}

/* Modal Styles */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal.hidden { display: none !important; }
.modal-content { background: var(--surface); border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0,0,0,0.5); }


.doofinder-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(255, 255, 255, 0.98);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}
.doofinder-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.doofinder-loader-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 250px;
    height: 250px;
}
.doofinder-spinner {
    position: absolute;
    width: 180px;
    height: 180px;
    border: 24px solid #e6e6f0;
    border-left: 24px solid transparent;
    border-radius: 50%;
    animation: doofinder-spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
.doofinder-loader-container p {
    position: absolute;
    color: #8c8c8c;
    font-family: Arial, sans-serif;
    font-size: 15px;
    margin: 0;
    text-align: center;
    white-space: nowrap;
    transform: translateY(5px);
}
@keyframes doofinder-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
