.button-spinner {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.5em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.1em;
  flex-shrink: 0;
  animation: button-spin 0.75s linear infinite;
}
button[aria-busy="true"] { cursor: wait; }
@keyframes button-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .button-spinner { animation: none; }
}
:root {
  --primary: #012f64;
  --background: #f3f5f8;
  --surface: #fff;
  --text: #1b2733;
  --muted: #5b6776;
  --border: #d6dde6;
  --accent: var(--primary);
  --danger: #c9392c;
}

* { box-sizing: border-box; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; margin: 0; color: var(--text); background: var(--background); }
header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.5rem; color: #fff; background: var(--primary); }
header h1 { margin: 0; font-size: 1.25rem; }
header nav a { color: #fff; text-underline-offset: .25rem; }
main { max-width: 1100px; margin: auto; padding: 1rem; }
h1 { font-size: 1.4rem; margin: 0 0 .5rem; overflow-wrap: anywhere; }
a { color: var(--accent); overflow-wrap: anywhere; }
nav { display: flex; gap: 1rem; flex-wrap: wrap; }
input, select, button, textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; max-width: 100%; }
input, select, textarea { background: var(--surface); color: var(--text); }
button { cursor: pointer; background: var(--surface); color: var(--primary); font-weight: 600; overflow-wrap: anywhere; }
button:hover { background: #e7edf4; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
label { display: inline-flex; gap: .4rem; align-items: center; }
.error, .danger { color: var(--danger); }
small { color: var(--muted); }

.login-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.login-page main { width: 364px; max-width: 100%; margin: 0; }
.login-form { background: var(--surface); padding: 2rem; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 2px 8px rgba(16, 27, 38, .1); }
.login-form label { display: block; margin-top: 1rem; }
.login-form input { width: 100%; margin-top: .25rem; }
.login-form button { margin-top: 1.5rem; width: 100%; padding: .6rem; background: var(--primary); color: var(--surface); border: 0; }
.login-form button:hover { background: #02417f; }
.login-form .error { margin-top: 1rem; }
.home-page main { max-width: 40rem; }
.home-page main { max-width: 70rem; }
.header-title { display: flex; align-items: center; gap: .5rem; }
.site-header h1 { margin: 0; }
.header-back-link { display: grid; width: 2rem; height: 2rem; flex: 0 0 auto; place-items: center; color: #fff; font-size: 1.6rem; line-height: 1; text-decoration: none; }
.header-back-link:focus-visible { outline-color: #fff; }
.header-actions, .header-actions nav { display: flex; align-items: center; gap: 1rem; }
.header-actions form { margin: 0; }
.header-actions button { background: #fff; color: var(--primary); }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin: 0 0 1rem; color: var(--muted); }
.breadcrumbs a { color: var(--accent); }
.dashboard-grid, .available-app-grid { display: grid; grid-auto-rows: 1fr; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.app-tile { position: relative; min-width: 0; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.app-tile:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 4px 14px rgba(16, 27, 38, .12); }
.app-tile-link { position: absolute; z-index: 1; inset: 0; border-radius: inherit; }
.app-tile-link:focus-visible { z-index: 3; }
.app-tile-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.app-tile-menu { position: relative; z-index: 4; flex: 0 0 auto; }
.app-tile-menu > summary { display: grid; width: 2rem; height: 2rem; place-items: center; padding: 0; border: 0; border-radius: 4px; background: transparent; color: #8995a3; font-size: 1.35rem; line-height: 1; list-style: none; cursor: pointer; }
.app-tile-menu > summary::-webkit-details-marker { display: none; }
.app-tile-menu > summary:hover { background: #f3f5f8; color: var(--text); }
.app-tile-menu > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.app-tile-menu[open] > .app-tile-popup { position: absolute; z-index: 5; top: calc(100% + .25rem); right: 0; width: 15rem; max-width: calc(100vw - 4rem); margin: 0; padding: .3rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); box-shadow: 0 4px 14px rgba(16, 27, 38, .12); }
.app-tile-popup a { display: block; padding: .45rem .6rem; border-radius: 4px; text-decoration: none; }
.app-tile-popup a:hover { background: #f3f5f8; }
.app-tile-popup form { margin: 0; }
.app-tile-menu form button { border: 0; background: transparent; color: var(--danger); }
.app-tile-menu form button:hover { background: #f3f5f8; }
.app-tile h3 { min-width: 0; margin: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.app-tile p { overflow-wrap: anywhere; color: var(--muted); white-space: pre-wrap; }
.app-tile iframe { position: relative; z-index: 2; display: block; width: 100%; height: 15rem; border: 0; background: transparent; pointer-events: none; }
.icon-button { display: inline-grid; width: 2rem; height: 2rem; place-items: center; padding: 0; line-height: 1; }
.icon-button > span { font-size: 1.2rem; }
.add-app-tile { display: grid; min-width: 0; min-height: 9rem; place-items: center; padding: 1rem; border: 1px dashed #8995a3; border-radius: 6px; background: var(--surface); color: var(--primary); text-decoration: none; }
.add-app-icon { font-size: 1.6rem; line-height: 1; }
.add-app-tile span { text-align: center; }
.app-dialog { width: min(960px, calc(100% - 2rem)); max-width: 960px; max-height: calc(100% - 2rem); padding: 1.25rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.app-dialog::backdrop { background: rgba(16, 27, 38, .5); }
.application-file-popup { position: fixed; inset: auto; z-index: 10; width: 16rem; max-width: calc(100vw - 1rem); margin: 0; padding: .3rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); box-shadow: 0 4px 14px rgba(16, 27, 38, .12); }
.application-file-popup > p { margin: 0; padding: .45rem .6rem; color: var(--muted); overflow-wrap: anywhere; }
.application-file-popup > hr { margin: .3rem .6rem; border: 0; border-top: 1px solid var(--border); }
.application-file-popup > button[hidden] + hr { display: none; }
.application-file-popup > button:not([hidden]) { display: block; width: 100%; border: 0; background: transparent; color: var(--text); font-weight: 400; text-align: left; }
.application-file-popup > button:hover { background: #f3f5f8; }
.application-file-popup > button:disabled { color: var(--muted); cursor: not-allowed; background: transparent; opacity: .6; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-bottom: .9rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 1.2rem; }
.available-app-tile { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: .75rem; padding: 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.available-app-tile h3, .available-app-tile p { margin: 0; overflow-wrap: anywhere; }
.available-app-tile .app-tile-heading { width: 100%; }
.available-app-tile p { color: var(--muted); white-space: pre-wrap; }
.available-app-tile form { margin-top: auto; }
.available-app-empty { grid-column: 1 / -1; margin: 0; color: var(--muted); }
.application-admin { display: grid; gap: 1rem; margin: 1rem 0 2rem; }
.application-admin details { margin: .7rem 0; padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.application-editor { display: grid; gap: 1rem; }
.application-editor label { display: grid; align-content: start; gap: .3rem; }
.application-editor input, .application-editor textarea, .application-editor select { width: 100%; min-width: 0; }
.application-editor textarea { min-height: 6rem; font-family: inherit; }
.application-editor-tokens { display: grid; gap: .8rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.application-editor-tokens legend { margin-bottom: .3rem; font-weight: 600; }
.application-editor-files { display: grid; gap: .5rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.application-editor-files[hidden] { display: none; }
.application-editor-files legend { margin-bottom: .3rem; font-weight: 600; }
.application-editor-help { margin: 0; color: var(--muted); }
.application-editor .application-save { justify-self: start; background: var(--primary); color: #fff; border-color: var(--primary); }
.application-delete { display: flex; justify-content: flex-end; padding-top: 1rem; border-top: 1px solid var(--border); }
.application-delete button { border-color: var(--danger); color: var(--danger); }
.app-wizard { display: grid; gap: 1rem; }
.application-wizard { margin: 1rem 0 2rem; }
.wizard-steps { display: flex; width: 100%; margin: 0 0 .5rem; padding: 0; list-style: none; counter-reset: step; }
.wizard-steps li { position: relative; display: flex; flex: 1 1 0; min-width: 0; flex-direction: column; align-items: center; gap: .4rem; padding: 0 .25rem; color: #8995a3; font-size: .9rem; text-align: center; overflow-wrap: anywhere; counter-increment: step; }
.wizard-steps li::before { content: counter(step); position: relative; z-index: 1; display: grid; width: 2rem; height: 2rem; place-items: center; border-radius: 50%; background: #e3e7ec; color: #6b7785; font-weight: 600; }
.wizard-steps li:not(:last-child)::after { content: ""; position: absolute; top: 1rem; left: calc(50% + 1.4rem); right: calc(-50% + 1.4rem); height: 1px; background: #c5ccd5; }
.wizard-steps li.done { color: var(--primary); }
.wizard-steps li.done::before { background: #e7edf4; color: var(--primary); }
.wizard-steps li.done::after { background: var(--primary); }
.wizard-steps li[aria-current="step"] { color: var(--primary); font-weight: 600; }
.wizard-steps li[aria-current="step"]::before { background: var(--primary); color: #fff; box-shadow: 0 0 0 4px #d5e0ec; }
.wizard-step { display: grid; gap: .8rem; min-width: 0; }
.wizard-step[hidden] { display: none; }
.wizard-step h2 { margin: .5rem 0 0; }
.wizard-step p { margin: 0; overflow-wrap: anywhere; }
.wizard-step > label { display: grid; gap: .3rem; }
.wizard-step textarea { min-height: 6rem; font-family: inherit; }
.wizard-table { min-height: 16rem; max-height: 24rem; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.wizard-table table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.application-file-list { table-layout: fixed; }
.application-file-list th:first-child, .application-file-list td:first-child { width: auto; max-width: none; }
.application-file-list th:nth-child(2), .application-file-list td:nth-child(2) { width: 7rem; }
.application-file-list th:nth-child(3), .application-file-list td:nth-child(3) { width: 8rem; }
.application-file-list th:nth-child(4), .application-file-list td:nth-child(4) { width: 13rem; }
.application-file-list th:nth-child(n+2), .application-file-list td:nth-child(n+2) { text-align: right; }
.wizard-table th, .wizard-table td { padding: .5rem 1rem; text-align: left; vertical-align: top; border-bottom: 1px solid #e7edf4; }
.wizard-table th { position: sticky; top: 0; background: #f8fafc; font-size: .8rem; font-weight: 600; color: var(--muted); }
.wizard-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wizard-table tr:last-child td { border-bottom: 0; }
.wizard-table tr.selectable { cursor: pointer; }
.wizard-table tr.selectable:hover td { background: #f3f5f8; }
.wizard-table tr.selected td { background: #e4edfa; color: var(--primary); font-weight: 600; }
.wizard-table tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.wizard-table tr.disabled td { color: #8995a3; }
.wizard-select { padding: 0; border: 0; background: transparent; color: inherit; font-weight: inherit; text-align: left; }
.wizard-select:hover { background: transparent; }
.wizard-select .wizard-file-badge { display: inline-block; margin-left: .5rem; padding: .08rem .35rem; border: 1px solid #c8d5e3; border-radius: 3px; background: #e7edf4; color: var(--primary); font-size: .75rem; font-weight: 600; white-space: nowrap; }
.wizard-empty { color: var(--muted); }
.wizard-inline { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem; }
.wizard-token-tags { display: flex; flex-wrap: wrap; gap: .5rem; min-height: 2.5rem; margin: 0; padding: 0; list-style: none; }
.wizard-token-tag { display: inline-flex; align-items: center; gap: .45rem; max-width: 100%; padding: .25rem .35rem .25rem .75rem; border: 1px solid #9bb6d2; border-radius: 999px; background: #e4edfa; color: #12395f; font-weight: 600; overflow-wrap: anywhere; }
.wizard-token-remove { display: grid; width: 1.4rem; height: 1.4rem; flex: 0 0 auto; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #365a7d; line-height: 1; }
.wizard-token-remove:hover { background: #c8d9ed; color: #12395f; }
.wizard-token-controls label { display: grid; gap: .3rem; align-items: start; }
.wizard-dropzone.drag-active { border-color: transparent; outline: 2px dashed #8995a3; outline-offset: -2px; }
.wizard-dropzone.dragging { outline-color: var(--primary); background: #e4edfa; }
.wizard-dropzone.dragging th, .wizard-dropzone.dragging td { background: transparent; }
.wizard-nav { display: flex; justify-content: space-between; gap: .5rem; }
.wizard-nav #wizard-next, .wizard-nav #wizard-finish { margin-left: auto; background: var(--primary); color: #fff; border-color: var(--primary); }
.wizard-nav button:disabled { cursor: not-allowed; opacity: .5; }

.toolbar { display: flex; gap: 1rem; flex-wrap: wrap; padding: 1rem 0; }
.toolbar form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; min-width: 0; }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .9rem; }
td, th { text-align: left; padding: .65rem 1rem; border-bottom: 1px solid #e7edf4; overflow-wrap: anywhere; }
th { background: #f8fafc; font-size: .8rem; font-weight: 600; color: var(--muted); }
td:first-child { max-width: 20rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions input[type=text] { width: 12rem; }
textarea { width: 100%; min-height: 60vh; font-family: monospace; tab-size: 4; }
.editor button { margin-top: 1rem; }
details { max-width: 100%; }
summary { cursor: pointer; }

@media (max-width: 650px) {
  .app-tile-heading { flex-wrap: wrap; }
  table, tbody, tr, td { display: block; }
  thead { display: none; }
  td:first-child { max-width: none; }
  td { border: 0; }
  tr { border-bottom: 1px solid var(--border); }
  .actions { width: 100%; }
  input[type=file] { width: 100%; }
}

@media (max-width: 760px) {
  .dashboard-grid, .available-app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .dashboard-grid, .available-app-grid { grid-template-columns: minmax(0, 1fr); }
  .site-header { align-items: flex-start; }
  .header-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .app-dialog { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .app-tile { transition: none; }
  .app-tile:hover { transform: none; }
}