:root {
  color-scheme: light dark;
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #1a1c20;
  --color-muted: #55595f;
  --color-border: #d3d7dc;
  --color-primary: #0b5fff;
  --color-primary-text: #ffffff;
  --color-error: #b3261e;
  --color-error-bg: #fdecea;
  --color-warning-bg: #fff4e0;
  --color-warning-text: #7a4a00;
  --color-success-bg: #e7f6ec;
  --color-success-text: #1e6b34;
  --color-info-bg: #e6f0ff;
  --color-info-text: #0b3d91;
  --focus-ring: #0b5fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14161a;
    --color-surface: #1e2126;
    --color-text: #f0f1f3;
    --color-muted: #b4b8bf;
    --color-border: #3a3f47;
    --color-primary: #4c8dff;
    --color-primary-text: #0b1420;
    --color-error: #ff8a80;
    --color-error-bg: #3a1a18;
    --color-warning-bg: #3a2c0f;
    --color-warning-text: #ffcf80;
    --color-success-bg: #10331d;
    --color-success-text: #7fe0a0;
    --color-info-bg: #142b4d;
    --color-info-text: #9fc4ff;
    --focus-ring: #7fb2ff;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

/* Varmistaa, että [hidden]-attribuutti piilottaa elementin aina, vaikka jokin
   luokka (esim. display: flex/grid) asettaisi sille muuten saman spesifisyyden
   display-arvon. Ilman tätä esim. "Poista logo" ei visuaalisesti piilota
   .file-preview-laatikkoa, vaikka tila päivittyisikin oikein. */
[hidden] {
  display: none !important;
}

.page-header,
main,
.page-footer {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.page-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.page-header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.page-header-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex: 0 0 auto;
}

.page-menu {
  position: relative;
  flex: 0 0 auto;
}

.page-menu-button {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.page-menu-button svg {
  width: 22px;
  height: 22px;
}

.page-menu-list {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 30;
  min-width: 12rem;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.page-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: none;
  background: none;
  color: var(--color-text);
  text-align: left;
  font-size: 0.95rem;
  border-radius: 6px;
  cursor: pointer;
}

.page-menu-item svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  color: var(--color-muted);
}

.page-menu-item:hover,
.page-menu-item:focus-visible {
  background: var(--color-warning-bg);
}

.page-header h1 {
  margin: 0;
  font-size: 1.75rem;
}

.lead {
  color: var(--color-muted);
  margin: 0;
}

.warning-banner {
  margin: 0 0 1.25rem 0;
  padding: 1rem;
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border: 1px solid var(--color-warning-text);
  border-radius: 8px;
}

.info-banner {
  margin: 0 0 1.25rem 0;
  padding: 1rem;
  background: var(--color-info-bg);
  color: var(--color-info-text);
  border: 1px solid var(--color-info-text);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.info-banner p {
  margin: 0;
}

.warning-banner p {
  margin: 0.25rem 0;
}

.section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.section h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

.advanced-summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.advanced-summary::-webkit-details-marker {
  display: none;
}

.advanced-summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.5rem;
  transition: transform 0.15s ease;
}

.advanced-details[open] .advanced-summary::before {
  transform: rotate(90deg);
}

.advanced-details > *:not(summary) {
  margin-top: 1rem;
}

.advanced-details h2 {
  font-size: 1.05rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.teams-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 700px) {
  .teams-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.team-fieldset {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1rem;
  min-width: 0;
}

.team-fieldset legend {
  font-weight: 600;
  padding: 0 0.4rem;
}

.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="file"],
select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
}

input[type="text"]:focus,
input[type="file"]:focus,
select:focus,
button:focus,
[tabindex]:focus {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.field-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

.char-counter {
  font-size: 0.85rem;
  color: var(--color-muted);
}

.field-error {
  color: var(--color-error);
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  margin: 0.5rem 0 0 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.warning-text {
  color: var(--color-warning-text);
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-text);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.combobox-wrapper {
  position: relative;
}

.suggestion-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 20;
  margin: 0.25rem 0 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  max-height: 14rem;
  overflow-y: auto;
}

.suggestion-option {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}

.suggestion-option-secondary {
  color: var(--color-muted);
  font-size: 0.8rem;
  margin-top: 0.1rem;
}

.suggestion-option:hover,
.suggestion-option.suggestion-option-active {
  background: var(--color-warning-bg);
}

.suggestion-option mark {
  background: none;
  color: inherit;
  font-weight: 700;
  padding: 0;
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 0.9rem;
}

.dropzone-icon {
  width: 28px;
  height: 28px;
  color: var(--color-muted);
}

.dropzone-text {
  margin: 0;
}

.dropzone-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropzone:focus-within,
.dropzone.dropzone-active {
  border-color: var(--color-primary);
  color: var(--color-text);
  background: var(--color-warning-bg);
}

.dropzone:focus-within .dropzone-icon,
.dropzone.dropzone-active .dropzone-icon {
  color: var(--color-primary);
}

.file-preview {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.logo-preview-image {
  max-width: 140px;
  max-height: 140px;
  object-fit: contain;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
}

.file-preview-info {
  min-width: 0;
  flex: 1 1 200px;
}

.file-name {
  font-weight: 600;
  margin: 0 0 0.15rem 0;
  overflow-wrap: anywhere;
}

.file-meta {
  color: var(--color-muted);
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
}

.file-list {
  list-style: none;
  margin: 0.75rem 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.file-list-item {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.6rem;
  background: var(--color-bg);
}

.file-list-item.dragging {
  opacity: 0.5;
}

.file-list-item.drag-over-before {
  box-shadow: 0 -3px 0 0 var(--color-primary);
}

.file-list-item.drag-over-after {
  box-shadow: 0 3px 0 0 var(--color-primary);
}

.drag-handle {
  flex: 0 0 auto;
  cursor: grab;
  color: var(--color-muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 0.15rem;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.file-list-thumb {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--color-muted);
  text-align: center;
}

.file-list-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-list-thumb-media {
  width: 200px;
  height: auto;
  max-width: 100%;
}

.file-list-thumb-media video,
.file-list-thumb-media audio {
  width: 100%;
  border-radius: 4px;
  background: #000;
}

.file-list-thumb-media audio {
  background: transparent;
}

.file-list-info {
  flex: 1 1 auto;
  min-width: 0;
}

.file-list-info .file-name {
  overflow-wrap: anywhere;
}

.file-list-order {
  font-variant-numeric: tabular-nums;
  color: var(--color-muted);
  font-size: 0.85rem;
}

.file-list-controls {
  display: flex;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.icon-button {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--color-primary);
}

.icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.checkbox-field input {
  width: 1.1rem;
  height: 1.1rem;
}

.tree-preview {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre;
}

.tech-details-toggle {
  margin-top: 1rem;
}

.tech-details-toggle #success-tech-details-wrap {
  margin-top: 0.75rem;
}

.tech-details-textarea {
  display: block;
  width: 100%;
  min-height: 14rem;
  margin-bottom: 0.6rem;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre;
  resize: vertical;
}

.summary-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}

.summary-list dt {
  font-weight: 600;
  color: var(--color-muted);
}

.summary-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.totals-info {
  margin: 0;
  color: var(--color-muted);
}

.write-section {
  text-align: center;
}

.hint-text {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.6rem auto 0 auto;
  max-width: 32rem;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.status-icon {
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
}

button {
  font-family: inherit;
  font-size: 1rem;
  border-radius: 8px;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  border: 1px solid transparent;
}

.button-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-weight: 700;
  border-color: var(--color-primary);
}

.button-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}

.progress-region {
  margin-top: 1rem;
  padding: 0.85rem;
  border-radius: 8px;
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.progress-region p {
  margin: 0.15rem 0;
}

.result-view {
  max-width: 1000px;
  margin: 0 auto 1.25rem auto;
  padding: 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--color-border);
}

.success-view {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-color: var(--color-success-text);
}

.error-view {
  background: var(--color-error-bg);
  color: var(--color-error);
  border-color: var(--color-error);
}

.result-view .summary-list dt,
.error-view p {
  color: inherit;
}

.result-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

dialog {
  border-radius: 10px;
  border: 1px solid var(--color-border);
  max-width: 560px;
  width: 100%;
  padding: 1.25rem;
  background: var(--color-surface);
  color: var(--color-text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.page-footer {
  color: var(--color-muted);
  font-size: 0.85rem;
  text-align: center;
}

fieldset {
  min-width: 0;
}
