:root {
  color-scheme: light;
  --background: #f5f4f4;
  --foreground: #1a1818;
  --card: #ffffff;
  --card-foreground: #1a1818;
  --muted: #f3f1f1;
  --muted-foreground: #635a5b;
  --primary: #c8102e;
  --primary-foreground: #ffffff;
  --primary-soft: #fce3e5;
  --secondary: #fbe7e9;
  --border: #e5e0e0;
  --input: #dad4d4;
  --ring: #c8102e;
  --sidebar: #131313;
  --sidebar-soft: #201f1f;
  --sidebar-accent: #2a2a2a;
  --sidebar-foreground: #e5e2e1;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #ba1a1a;
  --info: #4f7b96;
  --radius: 8px;
  --shadow: 0 16px 45px rgba(26, 24, 24, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--background);
  color: var(--foreground);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, var(--sidebar) 0 34%, transparent 34%),
    var(--background);
}

.login-card {
  display: grid;
  width: min(430px, 100%);
  gap: 16px;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand-block.plain {
  padding: 0 0 16px;
  color: var(--foreground);
  border-bottom-color: var(--border);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 750;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 20px 14px;
  background: var(--sidebar);
  color: var(--sidebar-foreground);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 12px;
  border-bottom: 1px solid var(--sidebar-accent);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 900;
  box-shadow:
    0 0 0 1px rgba(255, 90, 95, 0.36),
    0 0 18px rgba(255, 90, 95, 0.32);
}

.brand-kicker,
.top-kicker {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
}

h2 {
  font-size: 24px;
  line-height: 1.15;
}

h3 {
  font-size: 16px;
  line-height: 1.25;
}

.role-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--sidebar-soft);
  border: 1px solid var(--sidebar-accent);
  border-radius: var(--radius);
}

.side-label {
  color: #cbb9b9;
  font-size: 12px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #0f0f0f;
  border: 1px solid var(--sidebar-accent);
  border-radius: 7px;
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #cbb9b9;
  font-size: 13px;
  font-weight: 800;
}

.segmented button.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.side-nav {
  display: grid;
  gap: 4px;
}

.side-nav a,
.side-nav button {
  padding: 10px 12px;
  border-left: 2px solid transparent;
  border-radius: 6px;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  background: transparent;
  color: #d8d1d1;
  font-size: 14px;
  font-weight: 750;
  text-align: left;
  text-decoration: none;
}

.side-nav a:hover,
.side-nav a.active,
.side-nav button:hover,
.side-nav button.active {
  background: var(--sidebar-accent);
  border-left-color: var(--primary);
  color: var(--primary);
}

.main {
  min-width: 0;
  padding: 18px 20px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -18px -20px 18px;
  padding: 16px 20px;
  background: rgba(245, 244, 244, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.top-actions,
.row-actions,
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title p {
  margin-top: 4px;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 1.35;
}

.save-status {
  min-width: 88px;
  color: var(--muted-foreground);
  font-size: 13px;
  text-align: right;
}

.button,
.text-button,
.icon-button {
  border: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.button:disabled,
.text-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.button-primary:hover {
  background: #a60e27;
}

.button-secondary {
  background: var(--muted);
  color: var(--foreground);
}

.button-secondary:hover {
  background: #ebe6e6;
}

.text-button {
  padding: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 850;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat span {
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 750;
}

.stat strong {
  font-size: 28px;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 520px;
  gap: 18px;
  max-width: 1640px;
}

.panel {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-panel,
.message-panel,
.preview-panel,
.queue-panel {
  padding: 20px;
}

.side-stack {
  display: grid;
  align-self: start;
  gap: 18px;
}

.preview-panel {
  max-height: calc(100vh - 250px);
  overflow: auto;
}

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

label {
  display: grid;
  gap: 7px;
  color: #3f393a;
  font-size: 13px;
  font-weight: 750;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--input);
  border-radius: 6px;
  background: #fff;
  color: var(--foreground);
  outline: none;
}

input {
  min-height: 40px;
  padding: 8px 10px;
}

select {
  min-height: 40px;
  padding: 8px 10px;
}

textarea {
  min-height: 94px;
  padding: 10px;
  line-height: 1.45;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.13);
}

.compact-actions {
  justify-content: flex-end;
  margin: 14px 0;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

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

.item-title {
  margin-top: 28px;
}

.paste-box {
  margin-bottom: 14px;
}

.item-table-shell,
.queue-table-shell {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.item-table,
.queue-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.item-table {
  min-width: 1080px;
}

.queue-table {
  min-width: 980px;
}

.user-table {
  min-width: 1060px;
  table-layout: auto;
}

.user-table th:nth-child(2),
.user-table td:nth-child(2) {
  min-width: 230px;
}

.user-table th:nth-child(4),
.user-table td:nth-child(4) {
  min-width: 150px;
}

.item-table th,
.item-table td,
.queue-table th,
.queue-table td {
  border-bottom: 1px solid var(--border);
  background: var(--card);
  vertical-align: top;
}

.item-table th,
.queue-table th {
  padding: 10px 8px;
  background: #fbf8f8;
  color: #564c4d;
  font-size: 12px;
  font-weight: 850;
  text-align: left;
}

.item-table td,
.queue-table td {
  padding: 8px;
  font-size: 13px;
}

.user-table td {
  overflow-wrap: anywhere;
}

.queue-table tr.selected-row td {
  background: var(--primary-soft);
}

.item-table th:nth-child(1),
.item-table td:nth-child(1) {
  width: 48px;
  text-align: center;
}

.item-table th:nth-child(3),
.item-table td:nth-child(3) {
  width: 105px;
}

.item-table th:nth-child(4),
.item-table td:nth-child(4) {
  width: 90px;
}

.item-table th:nth-child(5),
.item-table td:nth-child(5) {
  width: 78px;
}

.item-table th:nth-child(6),
.item-table td:nth-child(6) {
  width: 120px;
}

.item-table th:nth-child(8),
.item-table td:nth-child(8) {
  width: 48px;
}

.item-table input,
.item-table textarea {
  min-height: 34px;
  border-color: transparent;
  background: #fbfafa;
  font-size: 13px;
}

.item-table textarea {
  min-height: 42px;
}

.index-cell {
  display: grid;
  place-items: center;
  min-height: 38px;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 850;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--danger);
  font-size: 18px;
}

.icon-button:hover {
  background: rgba(186, 26, 26, 0.1);
}

.queue-panel {
  max-width: 1640px;
  margin-top: 18px;
}

.standalone-queue {
  margin-top: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}

.status-pending {
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.13);
  color: #9a5500;
}

.status-approved {
  border-color: rgba(22, 163, 74, 0.35);
  background: rgba(22, 163, 74, 0.12);
  color: #11743a;
}

.status-rejected {
  border-color: rgba(186, 26, 26, 0.32);
  background: rgba(186, 26, 26, 0.1);
  color: var(--danger);
}

.request-code {
  color: var(--primary);
  font-weight: 850;
}

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

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

.mini-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--foreground);
  font-size: 12px;
  font-weight: 800;
}

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

.mini-button.approve {
  border-color: rgba(22, 163, 74, 0.35);
  color: var(--success);
}

.mini-button.reject {
  border-color: rgba(186, 26, 26, 0.35);
  color: var(--danger);
}

.message-panel textarea {
  min-height: 150px;
  background: #fffafa;
}

.paper {
  width: 100%;
  min-height: 560px;
  overflow-x: auto;
  padding: 24px 24px 28px;
  background: white;
  border: 1px solid #a59b9c;
  color: #111;
  font-family: Cambria, Georgia, serif;
  font-size: 11px;
  line-height: 1.34;
}

.empty-preview {
  display: grid;
  min-height: 320px;
  place-items: center;
  color: var(--muted-foreground);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 750;
}

.paper .company-lines {
  margin-bottom: 18px;
  text-align: center;
  line-height: 1.25;
}

.paper h3 {
  margin: 0 0 12px;
  font-size: 17px;
  line-height: 1.18;
  text-align: center;
  text-transform: uppercase;
}

.paper .paper-date {
  margin: 0 0 12px;
  text-align: right;
}

.paper p {
  margin: 5px 0;
}

.paper-table,
.sign-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.paper-table {
  margin-top: 8px;
}

.paper-table th,
.paper-table td {
  overflow-wrap: anywhere;
  border: 1px solid #111;
  padding: 5px;
  vertical-align: middle;
}

.paper-table th {
  font-weight: 700;
  text-align: center;
}

.paper-table .center {
  text-align: center;
}

.sign-table {
  margin-top: 14px;
  text-align: center;
}

.sign-table td {
  width: 33.33%;
  padding: 4px 6px;
  vertical-align: top;
}

.signature-space {
  height: 54px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.process-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.process-grid div,
.role-row {
  display: grid;
  gap: 6px;
  padding: 14px;
  background: #fbfafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.role-row {
  width: 100%;
  margin-top: 8px;
  color: var(--foreground);
  text-align: left;
}

.role-row.selected-role {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.process-grid span,
.role-row span,
.role-row small {
  color: var(--muted-foreground);
  line-height: 1.4;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  padding: 12px;
  background: #fbfafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.permission-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  font-size: 12px;
}

.permission-option input {
  width: auto;
  min-height: auto;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 12px;
  }

  .topbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    margin: -12px -12px 12px;
    padding: 14px 12px;
  }

  .top-actions,
  .row-actions,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-row,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .save-status {
    width: 100%;
    min-width: 0;
    text-align: left;
  }

  .preview-panel {
    overflow-x: hidden;
  }

  .paper {
    width: 100%;
    max-width: 100%;
    min-height: 460px;
    padding: 16px 12px 20px;
    font-size: 8px;
  }

  .paper h3 {
    font-size: 12px;
  }

  .paper-table th,
  .paper-table td {
    padding: 3px;
  }

  .signature-space {
    height: 38px;
  }
}

@media print {
  body {
    background: white;
  }

  .sidebar,
  .topbar,
  .stats-row,
  .form-panel,
  .message-panel,
  .queue-panel,
  .preview-panel > .section-title {
    display: none;
  }

  .app-shell,
  .main,
  .workspace,
  .side-stack {
    display: block;
    padding: 0;
  }

  .preview-panel,
  .paper {
    display: block;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
