:root {
  color-scheme: dark;
  --bg: #080b10;
  --bg-soft: #0d121a;
  --surface: #111823;
  --surface-strong: #172231;
  --surface-raised: #1c2a3b;
  --border: #26364a;
  --text: #f4f8fb;
  --muted: #98a8b9;
  --accent: #55d6be;
  --accent-strong: #2fbfa7;
  --accent-ink: #061512;
  --warm: #f0b76a;
  --danger: #ff7892;
  --issue-bg: rgba(85, 214, 190, 0.12);
  --issue-border: rgba(85, 214, 190, 0.34);
  --resolution-bg: rgba(255, 120, 146, 0.12);
  --resolution-border: rgba(255, 120, 146, 0.34);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --field-bg: #0d141d;
  --focus: 0 0 0 3px rgba(85, 214, 190, 0.22);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f5;
  --bg-soft: #eef1ee;
  --surface: #ffffff;
  --surface-strong: #f0f3ef;
  --surface-raised: #ffffff;
  --border: #d8ddd7;
  --text: #1d2320;
  --muted: #626d67;
  --accent: #168a68;
  --accent-strong: #0f7558;
  --accent-ink: #ffffff;
  --warm: #b55f14;
  --danger: #c73552;
  --issue-bg: rgba(22, 138, 104, 0.1);
  --issue-border: rgba(22, 138, 104, 0.26);
  --resolution-bg: rgba(199, 53, 82, 0.09);
  --resolution-border: rgba(199, 53, 82, 0.22);
  --shadow: 0 18px 40px rgba(30, 45, 38, 0.12);
  --field-bg: #ffffff;
  --focus: 0 0 0 3px rgba(22, 138, 104, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(145deg, rgba(85, 214, 190, 0.08), transparent 34%),
    linear-gradient(180deg, var(--bg-soft), var(--bg) 360px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

img {
  max-width: 100%;
}

main {
  flex: 1;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding: 14px clamp(16px, 4vw, 44px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
  font-weight: 800;
}

.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.brand-title,
.brand-wordmark {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-wordmark {
  font-size: 1rem;
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.nav-links a,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.nav-links a:hover,
.theme-toggle:hover,
.nav-links a.active {
  color: var(--text);
  background: var(--surface-strong);
  border-color: var(--border);
}

.logout-link {
  color: var(--danger) !important;
}

.page-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

.login-shell {
  position: relative;
  display: grid;
  min-height: calc(100vh - 45px);
  place-items: center;
  overflow: hidden;
  padding: 28px;
}

.login-shell::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black, transparent 78%);
  content: "";
}

.login-shell::after {
  position: absolute;
  right: 9vw;
  bottom: -80px;
  z-index: -1;
  width: min(540px, 78vw);
  height: 260px;
  border: 1px solid rgba(85, 214, 190, 0.22);
  border-radius: 28px 28px 0 0;
  background:
    linear-gradient(90deg, transparent 0 9%, rgba(85, 214, 190, 0.12) 9% 10%, transparent 10% 22%, rgba(255, 255, 255, 0.08) 22% 23%, transparent 23% 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.09), transparent);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
  content: "";
}

.login-card,
.form-card,
.settings-card,
.empty-state {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 26px;
  width: min(760px, 100%);
  padding: clamp(24px, 5vw, 40px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 42%),
    color-mix(in srgb, var(--surface) 94%, black);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.login-mark {
  display: inline-grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: var(--radius);
  color: var(--accent-ink);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.34), transparent 42%),
    var(--accent);
  box-shadow: 0 14px 32px rgba(85, 214, 190, 0.25);
  font-weight: 900;
}

.login-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

.login-brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
  grid-column: 1 / -1;
}

.login-card h1,
.page-heading h1 {
  margin: 0;
  line-height: 1.1;
}

.login-card h1 {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
}

.login-form {
  align-self: end;
}

.login-submit {
  width: 100%;
  margin-top: 2px;
  border: 0;
  box-shadow: 0 16px 34px rgba(85, 214, 190, 0.18);
}

.login-preview {
  display: grid;
  align-content: space-between;
  min-height: 210px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(85, 214, 190, 0.12), rgba(255, 120, 146, 0.08)),
    var(--field-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.preview-topline {
  width: 52%;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
}

.preview-row {
  display: grid;
  gap: 10px;
}

.preview-row span,
.preview-row strong,
.preview-columns span {
  display: block;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.preview-row span {
  width: 84%;
  height: 10px;
}

.preview-row strong {
  width: 66%;
  height: 10px;
}

.preview-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preview-columns span {
  height: 56px;
  border-radius: var(--radius);
}

.preview-columns span:first-child {
  background: var(--issue-bg);
  border: 1px solid var(--issue-border);
}

.preview-columns span:last-child {
  background: var(--resolution-bg);
  border: 1px solid var(--resolution-border);
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.page-heading h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.meta-line,
.muted,
.updated-text,
.usage-count {
  color: var(--muted);
}

.meta-line {
  margin: 8px 0 0;
}

.stack {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label,
.field > span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--field-bg);
  outline: none;
}

input:focus,
select:focus,
.editor-surface:focus {
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.edit-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: 10px 15px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 800;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.primary-button {
  color: var(--accent-ink);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.26), transparent 46%),
    var(--accent);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.edit-button:hover {
  transform: translateY(-1px);
}

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

.ghost-button {
  color: var(--muted);
  background: transparent;
  border-color: var(--border);
}

.danger-button {
  color: var(--danger);
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 48%, var(--border));
}

.compact {
  min-height: 36px;
  padding: 7px 11px;
}

.control-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 210px) minmax(130px, 170px) minmax(105px, 130px) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent),
    var(--surface);
  box-shadow: var(--shadow);
}

.control-actions {
  display: flex;
  gap: 8px;
}

.issue-list {
  display: grid;
  gap: 12px;
}

.issue-card {
  display: grid;
  grid-template-columns: minmax(145px, 175px) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.028), transparent),
    var(--surface);
  box-shadow: var(--shadow);
}

.date-cell,
.log-cell {
  min-width: 0;
  padding: 14px;
  border-radius: var(--radius);
}

.date-cell {
  display: grid;
  align-content: start;
  gap: 10px;
  background: var(--surface-strong);
  border: 1px solid rgba(255, 255, 255, 0.035);
}

.date-text {
  font-size: 0.98rem;
  font-weight: 850;
}

.department-pill {
  display: inline-flex;
  width: fit-content;
  padding: 4px 9px;
  border: 1px solid color-mix(in srgb, var(--warm) 48%, transparent);
  border-radius: 999px;
  color: var(--warm);
  font-size: 0.78rem;
  font-weight: 850;
}

.updated-text {
  font-size: 0.8rem;
}

.log-cell h2 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

.issue-cell {
  border: 1px solid var(--issue-border);
  background: var(--issue-bg);
}

.resolution-cell {
  border: 1px solid var(--resolution-border);
  background: var(--resolution-bg);
}

.rich-text {
  overflow-wrap: anywhere;
}

.rich-text > :first-child {
  margin-top: 0;
}

.rich-text > :last-child {
  margin-bottom: 0;
}

.rich-text a {
  color: var(--accent);
  font-weight: 750;
}

.attachment-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  text-decoration: none;
  font-size: 0.84rem;
}

.attachment-chip img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 5px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-button {
  align-self: start;
  color: var(--accent-ink);
  background: var(--accent);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  color: var(--muted);
}

.pagination > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 12px;
  padding: 34px;
}

.empty-state h1,
.empty-state h2,
.settings-card h2,
.existing-attachments h2 {
  margin: 0;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.form-card {
  padding: clamp(18px, 3vw, 28px);
}

.editor {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--field-bg);
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-strong);
}

.editor-toolbar button {
  min-width: 34px;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  font-weight: 850;
}

.editor-surface {
  min-height: 170px;
  padding: 13px;
  border: 1px solid transparent;
  outline: none;
}

.editor-surface:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-card {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 20px;
}

.wide-card {
  grid-column: 1 / -1;
}

.logo-preview {
  width: min(220px, 100%);
  max-height: 110px;
  object-fit: contain;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.department-list {
  display: grid;
  gap: 10px;
}

.department-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.department-row form {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.department-row input {
  min-width: 0;
}

.existing-attachments {
  display: grid;
  gap: 12px;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.attachment-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.attachment-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
}

.pdf-icon {
  display: grid;
  min-height: 90px;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-weight: 900;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--danger);
  font-weight: 800;
}

.checkbox-line input {
  width: auto;
  min-height: auto;
}

.toast {
  position: fixed;
  right: 22px;
  top: 92px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition:
    opacity 260ms ease,
    transform 260ms ease;
}

.toast-success {
  border-color: var(--issue-border);
}

.toast-error {
  border-color: var(--resolution-border);
}

.toast button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-strong);
}

.toast-hiding {
  opacity: 0;
  transform: translateY(-8px);
}

.app-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 45px;
  padding: 12px 16px;
  color: color-mix(in srgb, var(--muted) 82%, transparent);
  font-size: 0.78rem;
}

.app-footer span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-footer span + span::before {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.55;
  content: "";
}

@media (max-width: 920px) {
  .app-header,
  .page-heading,
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .control-bar,
  .issue-card,
  .settings-grid,
  .department-row,
  .login-card {
    grid-template-columns: 1fr;
  }

  .login-preview {
    min-height: 150px;
  }

  .edit-button {
    justify-self: stretch;
  }

  .control-actions,
  .pagination > div {
    flex-wrap: wrap;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .app-header {
    padding: 12px 10px;
  }

  .nav-links a,
  .theme-toggle {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 0.88rem;
  }

  .control-actions,
  .form-actions,
  .add-row,
  .department-row form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 24px;
  }

  .login-brand-block {
    align-items: flex-start;
    flex-direction: column;
  }

  .login-logo {
    width: 58px;
    height: 58px;
  }

  .login-preview {
    display: none;
  }

  .toast {
    right: 10px;
    left: 10px;
    top: 12px;
  }
}
