:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #657188;
    --primary: #1a3f74;
    --border: #dbe2ee;
    --danger: #b42318;
    --success: #067647;
    --warning: #b54708;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Tahoma, Arial, sans-serif; }
a { color: var(--primary); text-decoration: none; }
.container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.topbar { background: #0f2748; color: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.15); }
.topbar-inner { min-height: 64px; display: flex; align-items: center; gap: 18px; }
.brand { color: #fff; font-weight: 800; font-size: 20px; }
.subtitle { color: #bdd0eb; font-size: 14px; }
.page { padding: 28px 0 60px; }
.hero { margin-bottom: 18px; }
.hero h1, .build-header h1 { margin: 0 0 8px; }
.hero p, .build-header p { margin: 0; color: var(--muted); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: 0 8px 24px rgba(31,49,82,.06); margin-bottom: 20px; }
.form-section { padding: 0 0 22px; margin-bottom: 22px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: 0; }
h2 { font-size: 18px; margin: 0 0 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 700; }
input, select { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 12px; background: #fff; font: inherit; }
input:focus, select:focus { outline: 2px solid rgba(26,63,116,.18); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 3px; height: 42px; min-width: 54px; }
.color-control { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; }
small, .hint { color: var(--muted); font-weight: 400; }
.package-input { display: flex; direction: ltr; width: 100%; }
.package-prefix { display: inline-flex; align-items: center; padding: 10px 12px; border: 1px solid #cbd5e1; border-right: 0; border-radius: 8px 0 0 8px; background: #eef2f7; color: #334155; font-family: Consolas, monospace; white-space: nowrap; }
.package-input input { border-radius: 0 8px 8px 0; direction: ltr; }
.package-input:focus-within { border-radius: 8px; outline: 2px solid rgba(26,63,116,.18); }
.package-input:focus-within .package-prefix, .package-input:focus-within input { border-color: var(--primary); outline: 0; }

.color-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 14px; }
.checks label { flex-direction: row; align-items: center; }
.btn-primary, .btn-download { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 9px; padding: 11px 18px; background: var(--primary); color: #fff; font-weight: 800; cursor: pointer; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-download { margin-inline-start: 8px; font-size: 13px; }
.alert { border-radius: 9px; padding: 12px 14px; margin: 10px 0; }
.alert-warning { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.alert-info { background: #eff6ff; color: #1e3a8a; border: 1px solid #bfdbfe; }
.alert-danger { background: #fff1f0; color: var(--danger); border: 1px solid #fecdca; }
.validation, [data-valmsg-for] { color: var(--danger); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { color: var(--muted); font-size: 13px; }
.status { display: inline-flex; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; background: #eef2f7; }
.status-succeeded { color: var(--success); background: #ecfdf3; }
.status-failed, .status-cancelled { color: var(--danger); background: #fff1f0; }
.status-running { color: #175cd3; background: #eff8ff; }
.status-queued { color: var(--warning); background: #fffaeb; }
.build-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.back-link { display: inline-block; margin-bottom: 10px; }
.build-summary { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.build-summary > div { display: flex; flex-direction: column; gap: 6px; }
.build-summary .alert { grid-column: 1 / -1; }
.panel-title-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.build-log { direction: ltr; text-align: left; background: #0b1220; color: #d5e2f5; border-radius: 10px; padding: 16px; min-height: 420px; max-height: 65vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font-family: Consolas, monospace; font-size: 13px; }
.hidden { display: none !important; }
code { direction: ltr; display: inline-block; }

@media (max-width: 850px) {
    .grid-2, .build-summary { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .color-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .topbar-inner, .panel-title-row { align-items: flex-start; flex-direction: column; padding-block: 14px; }
}

/* Build progress and result states */
.build-state-card {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 18px;
    align-items: center;
    margin-bottom: 20px;
    padding: 22px;
    border: 1px solid #bfdbfe;
    border-radius: 14px;
    background: #eff8ff;
    box-shadow: 0 8px 24px rgba(31,49,82,.06);
}
.state-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(23,92,211,.1);
    color: #175cd3;
}
.state-content h2 { margin: 0 0 6px; font-size: 22px; }
.state-content p { margin: 0 0 16px; color: var(--muted); }
.large-spinner, .button-spinner {
    display: inline-block;
    border-radius: 50%;
    border-style: solid;
    border-color: currentColor transparent currentColor currentColor;
    animation: spin .8s linear infinite;
}
.large-spinner { width: 34px; height: 34px; border-width: 4px; }
.button-spinner { width: 17px; height: 17px; border-width: 2px; margin-inline-end: 8px; vertical-align: -3px; }
.state-symbol { font-size: 38px; line-height: 1; font-weight: 900; }
.progress-row { display: grid; grid-template-columns: minmax(0,1fr) 52px; gap: 12px; align-items: center; }
.progress-track { height: 12px; overflow: hidden; border-radius: 999px; background: rgba(15,39,72,.12); }
.progress-bar { height: 100%; border-radius: inherit; background: #175cd3; transition: width .5s ease; position: relative; }
.state-running .progress-bar::after, .state-queued .progress-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
    transform: translateX(-100%);
    animation: progress-shine 1.4s infinite;
}
.state-succeeded { background: #ecfdf3; border-color: #abefc6; }
.state-succeeded .state-icon { color: var(--success); background: #d1fadf; }
.state-succeeded .progress-bar { background: var(--success); }
.state-failed, .state-cancelled { background: #fff1f0; border-color: #fecdca; }
.state-failed .state-icon, .state-cancelled .state-icon { color: var(--danger); background: #fee4e2; }
.state-failed .progress-bar, .state-cancelled .progress-bar { background: var(--danger); }
.error-prominent { display: flex; flex-direction: column; gap: 7px; font-size: 15px; }
.error-prominent strong { font-size: 17px; }
.artifacts-panel { border-color: #c7d7ef; }
.artifacts-list { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.artifacts-list .btn-download { margin: 0; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 220px; }
.artifacts-list .btn-download small { color: rgba(255,255,255,.82); font-size: 11px; font-weight: 400; direction: ltr; }
.btn-download-secondary { background: #475467; }
.build-log { white-space: normal; }
.log-line { min-height: 18px; white-space: pre-wrap; word-break: break-word; }
.log-error { color: #ff8a80; font-weight: 700; background: rgba(180,35,24,.12); }
.log-success { color: #75e0a7; }
.log-command { color: #84caff; font-weight: 700; }
.submit-loading { margin-top: 12px; color: var(--primary); font-weight: 700; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes progress-shine { to { transform: translateX(100%); } }

@media (max-width: 700px) {
    .build-state-card { grid-template-columns: 1fr; text-align: center; }
    .state-icon { margin: 0 auto; }
    .artifacts-list { width: 100%; justify-content: stretch; }
    .artifacts-list .btn-download { width: 100%; }
}


/* Build history and actions */
.hero-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.hero-copy { min-width: 0; }
.hero-copy h1 { margin-bottom: 7px; }
.hero-copy p { max-width: 720px; }
.hero-action-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.application-form-panel { scroll-margin-top: 18px; }
.app-form-toggle { gap: 10px; min-width: 145px; }
.app-form-toggle-icon { display: inline-block; font-size: 20px; line-height: 1; transition: transform .18s ease; transform: rotate(0deg); }
.app-form-toggle.is-open .app-form-toggle-icon { transform: rotate(180deg); }
.apps-count { display: inline-flex; min-width: 34px; align-items: center; justify-content: center; border-radius: 999px; padding: 7px 11px; background: #eef4ff; color: #175cd3; font-size: 13px; font-weight: 800; }
.empty-state { padding: 26px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); background: #fafcff; }
.package-name { color: #475467; font-size: 12px; overflow-wrap: anywhere; }
.app-actions, .completed-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.completed-actions { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.inline-form { display: inline-flex; margin: 0; }
.btn-secondary, .btn-success, .btn-ghost { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 9px; padding: 11px 18px; font: inherit; font-weight: 800; cursor: pointer; text-decoration: none; }
.btn-secondary { color: #344054; background: #eef2f7; }
.btn-success { color: #fff; background: var(--success); }
.btn-ghost { color: var(--primary); background: #fff; border: 1px solid #c7d7ef; }
.btn-small { padding: 8px 11px; font-size: 12px; }
.check-row { flex-direction: row; align-items: center; align-self: end; }

.builds-list-panel { border-color: #c7d7ef; }
.builds-list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.builds-list-heading { display: flex; align-items: center; gap: 10px; }
.builds-list-heading h2 { margin: 0; }
.app-search-label { width: min(420px, 100%); }
.app-search { padding-inline-start: 14px; }
.build-list-scroll {
    max-height: 620px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    padding-inline-end: 6px;
    padding-block: 2px;
    border-radius: 12px;
}
.build-list-scroll:focus-visible { outline: 2px solid rgba(26,63,116,.22); outline-offset: 4px; }
.build-list-scroll::-webkit-scrollbar { width: 10px; }
.build-list-scroll::-webkit-scrollbar-track { background: transparent; }
.build-list-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border: 2px solid transparent; border-radius: 999px; background-clip: content-box; }
.build-list-scroll::-webkit-scrollbar-thumb:hover { background: #98a2b3; background-clip: content-box; }
.build-list { display: flex; flex-direction: column; gap: 12px; }
.build-list-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: center; padding: 17px; border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: 0 4px 14px rgba(31,49,82,.04); }
.build-list-main { min-width: 0; }
.build-list-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.build-list-title-row h3 { margin: 0 0 6px; font-size: 17px; }
.build-list-details { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 15px 0 0; }
.build-list-details div { min-width: 0; }
.build-list-details dt { color: var(--muted); font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.build-list-details dd { margin: 0; font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.build-list-actions { justify-content: flex-end; max-width: 310px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

/* Keep hidden authoritative; prevents empty states from appearing when not needed. */
.hidden { display: none !important; }

@media (max-width: 950px) {
    .build-list-item { grid-template-columns: 1fr; }
    .build-list-actions { justify-content: flex-start; max-width: none; }
}

@media (max-width: 850px) {
    .hero-actions, .builds-list-toolbar { align-items: stretch; flex-direction: column; }
    .hero-action-group { width: 100%; }
    .hero-action-group > * { flex: 1 1 auto; }
    .app-search-label { width: 100%; }
    .build-list-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .build-list-scroll { max-height: 560px; padding-inline-end: 3px; }
}

@media (max-width: 520px) {
    .build-list-title-row { align-items: flex-start; }
    .build-list-details { grid-template-columns: 1fr; }
    .app-actions > *, .completed-actions > * { width: 100%; }
    .inline-form button { width: 100%; }
}

/* Separated build variants */
.build-options-secondary { margin-bottom: 18px; }
.build-variant-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.build-variant-card {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 18px;
    border: 1px solid #c7d7ef;
    border-radius: 12px;
    background: #f8fbff;
    color: var(--text);
    text-align: right;
    font: inherit;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.build-variant-card:hover { border-color: var(--primary); box-shadow: 0 8px 20px rgba(26,63,116,.12); transform: translateY(-1px); }
.build-variant-card.is-selected { border-color: var(--primary); background: #eef4ff; box-shadow: 0 0 0 2px rgba(26,63,116,.12); }
.build-variant-card:focus-visible { outline: 3px solid rgba(26,63,116,.2); border-color: var(--primary); }
.build-variant-card strong { color: var(--primary); font-size: 17px; text-align: center; }
.build-variant-card span { color: var(--muted); font-size: 13px; line-height: 1.7; }
.build-variant-card code { display: block; padding: 10px; border-radius: 8px; background: #0b1220; color: #d5e2f5; font-size: 11px; line-height: 1.6; white-space: normal; overflow-wrap: anywhere; text-align: left; }
.build-variant-card:disabled, .build-variant-card.is-submitting { opacity: .58; cursor: wait; transform: none; }

@media (max-width: 950px) {
    .build-variant-grid { grid-template-columns: 1fr; }
}


/* Authentication and users */
.topbar-user-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; }
.user-chip { display: inline-flex; align-items: center; min-height: 34px; padding: 7px 12px; border-radius: 999px; background: rgba(255,255,255,.12); color: #fff; font-weight: 800; font-size: 13px; }
.topbar-link, .topbar-logout { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 7px 11px; border-radius: 8px; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.28); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.auth-shell { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.auth-card { width: min(430px, 100%); margin-inline: auto; }
.auth-card h1 { margin: 0 0 20px; }
.auth-card form, .user-create-panel form { display: flex; flex-direction: column; gap: 15px; }
.auth-remember { align-self: flex-start; }
.auth-remember-hint { margin-top: -8px; line-height: 1.7; }
.auth-submit { width: 100%; }
.access-denied-card { text-align: center; }
.users-layout { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.user-create-panel { position: sticky; top: 20px; }
.users-list-panel { min-width: 0; }

@media (max-width: 850px) {
    .topbar-user-actions { margin-inline-start: 0; width: 100%; flex-wrap: wrap; }
    .users-layout { grid-template-columns: 1fr; }
    .user-create-panel { position: static; }
}
