:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #d9dde3;
  --text: #1d232b;
  --muted: #5f6b7a;
  --primary: #0b5cad;
  --primary-hover: #094c90;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --info-bg: #eef4fb;
  --success: #1a7f37;
  --warning: #c27c0e;
  --radius: 8px;
  --rail-width: 240px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.signin-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 420px;
  text-align: center;
}

.signin-box h1 {
  margin-top: 0;
  font-size: 1.5rem;
}

.signin-error-title {
  margin: 0 0 6px;
}

.signin-box details {
  text-align: left;
  font-size: 0.85rem;
}

.signin-error-detail {
  display: block;
  margin-top: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

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

.button-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button-inactive {
  opacity: 0.55;
}

.button-link {
  border: none;
  background: none;
  padding: 2px 4px;
  color: var(--primary);
}

.button-link:hover:not(:disabled) {
  text-decoration: underline;
}

/* Alerts */
.alert {
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0 0 16px;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecdca;
}

.alert-info {
  background: var(--info-bg);
  border: 1px solid #c7dcf2;
}

/* Page layout */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-dragging .main {
  outline: 3px dashed var(--primary);
  outline-offset: -8px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.layout {
  flex: 1;
  display: flex;
  align-items: flex-start;
}

.rail {
  position: sticky;
  top: 0;
  width: var(--rail-width);
  flex-shrink: 0;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  align-self: stretch;
}

.rail-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.rail-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 4px;
  border: none;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
}

.rail-item:hover {
  background: var(--bg);
}

.rail-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--muted);
}

.dot-complete {
  background: var(--primary);
  border-color: var(--primary);
}

.dot-uploading {
  border-color: var(--warning);
  background: var(--warning);
  animation: pulse 1s infinite alternate;
}

.dot-done {
  background: var(--success);
  border-color: var(--success);
}

.dot-failed {
  background: var(--danger);
  border-color: var(--danger);
}

@keyframes pulse {
  to {
    opacity: 0.35;
  }
}

.main {
  flex: 1;
  min-width: 0;
  padding: 20px 20px 96px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 64px 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  cursor: pointer;
}

.dropzone:hover {
  border-color: var(--primary);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  scroll-margin-top: 16px;
}

.card-failed {
  border-color: var(--danger);
}

.card-done {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.card-done > span:nth-child(2) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-error {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.card-body {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: 20px;
}

.preview {
  height: 420px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #eceff3;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.progress {
  position: relative;
  height: 24px;
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar {
  height: 100%;
  background: #b9d4f0;
  transition: width 0.2s;
}

.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 0.85rem;
}

/* Form */
.form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  align-content: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field:has(textarea) {
  grid-column: 1 / -1;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
  font-weight: 600;
}

.apply-all {
  font-size: 0.8rem;
  font-weight: normal;
}

.field input,
.field select,
.field textarea,
.date-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--surface);
}

.field textarea {
  resize: vertical;
}

.field-error input,
.field-error select,
.field-error textarea,
.field-error .date-input,
.field-error .amount-input input {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.field-message {
  color: var(--danger);
  font-size: 0.85rem;
}

.date-input {
  position: relative;
  min-height: 38px;
}

.date-input-empty span {
  color: var(--muted);
}

.date-input input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.date-input:has(input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.amount-input {
  position: relative;
}

.amount-input span {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.field .amount-input input {
  padding-left: 22px;
}

/* Bottom bar */
.bottombar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgb(0 0 0 / 0.05);
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .rail {
    position: static;
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .card-body,
  .form {
    grid-template-columns: 1fr;
  }
}
