:root {
  --black: #050505;
  --ink: #151515;
  --muted: #6b7280;
  --line: #d7dce2;
  --panel: #ffffff;
  --canvas: #f5f6f8;
  --red: #e30613;
  --red-dark: #b6000a;
  --green: #0d7a52;
  --shadow: 0 18px 45px rgba(12, 16, 24, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #eef1f4;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #050505;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(430px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  color: var(--ink);
  background: white;
  border-top: 6px solid var(--red);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card img {
  width: min(250px, 100%);
  padding: 16px;
  background: var(--black);
  border-radius: 6px;
}

.login-card h1 {
  font-size: 2rem;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--red-dark);
  font-weight: 800;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px 24px;
  color: white;
  background: var(--black);
  border-right: 7px solid var(--red);
}

.brand-block {
  min-height: 112px;
  display: flex;
  align-items: center;
}

.brand-block img {
  width: min(100%, 255px);
  height: auto;
  display: block;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  min-height: 44px;
  padding: 10px 12px;
  color: #d7dce2;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  text-align: left;
}

.nav-tab.active {
  color: white;
  background: var(--red);
  border-color: var(--red);
}

.company-meta {
  margin-top: auto;
  display: grid;
  gap: 6px;
  color: #c9ced5;
  font-size: 0.9rem;
  line-height: 1.35;
}

.company-meta strong {
  color: white;
}

.workspace {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 3rem);
}

h2 {
  font-size: 1.05rem;
}

.status-chip,
.connection-chip,
.preview-toolbar span,
.section-title span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--red-dark);
  background: #fff0f1;
  border: 1px solid #ffd2d6;
  font-weight: 800;
  white-space: nowrap;
}

.connection-chip {
  color: var(--green);
  background: #edf8f3;
  border-color: #c9ecdf;
}

.connection-chip.offline {
  color: #8a5a00;
  background: #fff7df;
  border-color: #f3dfa5;
}

.install-button[hidden] {
  display: none;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 20px;
  align-items: start;
}

.work-order-form,
.preview-panel,
.form-section,
.integration-flow {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(12, 16, 24, 0.04);
}

.work-order-form {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.form-section {
  padding: 18px;
}

.section-title,
.preview-toolbar,
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

label span,
legend {
  color: #30343a;
  font-size: 0.88rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cdd3db;
  border-radius: 6px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.12);
}

.machine-toggle {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}

.machine-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.machine-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--red);
}

.time-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.time-head,
.time-row {
  display: grid;
  grid-template-columns: 105px repeat(6, minmax(104px, 1fr));
  min-width: 780px;
}

.time-head span,
.time-row > * {
  min-height: 44px;
  padding: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.time-head span {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fb;
  font-weight: 900;
}

.time-row:last-child > * {
  border-bottom: 0;
}

.time-row > strong {
  display: flex;
  align-items: center;
}

.time-cell,
.time-total {
  display: grid;
  gap: 5px;
}

.time-cell span,
.time-total span {
  display: none;
}

.time-row input {
  min-height: 36px;
  padding: 6px 8px;
}

.time-row output {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-weight: 900;
}

.time-total output {
  min-height: 36px;
}

.signature-pad {
  position: relative;
  background: var(--canvas);
  border: 1px dashed #aeb7c2;
  border-radius: 8px;
  margin-top: 14px;
  min-height: 188px;
  overflow: hidden;
}

.signature-pad canvas {
  display: block;
  width: 100%;
  height: 190px;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}

.ghost-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  min-height: 36px;
  padding: 8px 12px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 800;
}

.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px;
  background: rgba(238, 241, 244, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 8px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 900;
  border: 1px solid transparent;
  text-decoration: none;
}

.primary-button {
  color: white;
  background: var(--red);
  border-color: var(--red);
}

.primary-button:hover {
  background: var(--red-dark);
}

.secondary-button {
  color: var(--ink);
  background: white;
  border-color: #bfc6d0;
}

.scan-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  color: white;
  background: var(--red);
  border: 1px solid var(--red);
  border-radius: 6px;
  font-weight: 900;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.scan-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.scan-empty {
  padding: 12px;
  color: var(--muted);
  background: #f8f9fb;
  border: 1px dashed #cdd3db;
  border-radius: 6px;
}

.scan-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.scan-card img,
.scan-file-icon {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  object-fit: cover;
  background: white;
  border: 1px solid #cdd3db;
}

.scan-file-icon {
  display: grid;
  place-items: center;
  color: var(--red-dark);
  font-weight: 900;
}

.scan-card strong,
.scan-card span {
  display: block;
}

.scan-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.preview-panel {
  position: sticky;
  top: 24px;
  padding: 14px;
}

.workbon-preview {
  overflow: hidden;
  background: white;
  border: 1px solid #cfd5dd;
  border-radius: 4px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  color: white;
  background: var(--black);
  border-bottom: 6px solid var(--red);
}

.preview-header img {
  width: 175px;
}

.preview-header h2 {
  color: #d8dce1;
  font-size: 1.7rem;
  text-align: right;
}

.preview-header p {
  margin: 5px 0 0;
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: right;
}

.preview-body {
  padding: 18px;
  display: grid;
  gap: 12px;
  font-size: 0.9rem;
}

.preview-line {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px;
  border-bottom: 1px solid #c8ced6;
  min-height: 26px;
}

.preview-line strong {
  font-weight: 900;
}

.preview-text {
  min-height: 52px;
  white-space: pre-wrap;
}

.mini-hours {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.mini-hours th,
.mini-hours td {
  border: 1px solid #c8ced6;
  padding: 5px;
  text-align: left;
}

.mini-hours th {
  background: #f3f5f7;
}

.signature-image {
  max-width: 100%;
  height: 70px;
  object-fit: contain;
  object-position: left center;
}

.list-header,
.settings-layout {
  margin-bottom: 18px;
}

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

.order-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.order-card strong {
  display: block;
  margin-bottom: 5px;
}

.order-card span {
  color: var(--muted);
}

.order-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact-button {
  min-height: 34px;
  padding: 7px 10px;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
}

.integration-flow {
  padding: 18px;
  display: grid;
  gap: 10px;
}

.mail-status-box {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding: 12px;
  color: #5d4300;
  background: #fff7df;
  border: 1px solid #f3dfa5;
  border-radius: 6px;
}

.mail-status-box.ready {
  color: var(--green);
  background: #edf8f3;
  border-color: #c9ecdf;
}

.mail-status-box span {
  color: inherit;
  font-weight: 700;
}

.flow-step {
  padding: 12px;
  border-radius: 6px;
  background: #f5f6f8;
  border-left: 4px solid #aeb7c2;
  font-weight: 800;
}

.flow-step.done {
  border-left-color: var(--green);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 15px;
  color: white;
  background: #191d23;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

#printArea {
  display: none;
}

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

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 7px solid var(--red);
  }

  .nav-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .company-meta {
    display: none;
  }

  .content-grid,
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  body {
    background: white;
  }

  .workspace,
  .sidebar {
    padding: 14px;
  }

  .sidebar {
    gap: 12px;
    border-bottom-width: 5px;
  }

  .brand-block {
    min-height: 58px;
  }

  .brand-block img {
    width: 185px;
  }

  .workspace {
    display: grid;
    gap: 12px;
  }

  h1 {
    font-size: 1.45rem;
  }

  h2 {
    font-size: 1rem;
  }

  .topbar,
  .section-title,
  .list-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .connection-chip,
  .status-chip,
  .preview-toolbar span,
  .section-title span {
    min-height: 28px;
    padding: 5px 9px;
    font-size: 0.82rem;
  }

  .work-order-form,
  .form-section,
  .preview-panel,
  .integration-flow,
  .order-card {
    border-radius: 0;
    box-shadow: none;
  }

  .work-order-form {
    padding: 0;
    border: 0;
    gap: 12px;
  }

  .form-section {
    padding: 14px;
    border-left: 0;
    border-right: 0;
  }

  .field-grid.two {
    grid-template-columns: 1fr;
  }

  input,
  textarea {
    min-height: 48px;
    font-size: 16px;
    padding: 12px;
  }

  textarea {
    min-height: 96px;
  }

  .machine-toggle {
    display: grid;
    gap: 10px;
  }

  .machine-toggle label {
    min-height: 44px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
  }

  .time-table {
    overflow: visible;
    border: 0;
  }

  .time-head {
    display: none;
  }

  .time-row {
    min-width: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8f9fb;
  }

  .time-row > * {
    min-height: 0;
    padding: 0;
    border: 0;
  }

  .time-row .time-day {
    grid-column: 1 / -1;
    align-items: center;
    min-height: 34px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--line);
  }

  .time-cell span,
  .time-total span {
    display: block;
    color: #30343a;
    font-size: 0.78rem;
    font-weight: 900;
  }

  .time-row input,
  .time-total output {
    min-height: 44px;
    padding: 10px;
    background: white;
    border: 1px solid #cdd3db;
    border-radius: 6px;
  }

  .time-total output {
    justify-content: flex-start;
  }

  .signature-pad {
    min-height: 235px;
  }

  .signature-pad canvas {
    height: 235px;
  }

  .action-bar {
    display: grid;
    grid-template-columns: 1fr;
    padding: 12px 0 0;
    background: white;
    backdrop-filter: none;
    position: static;
  }

  .primary-button,
  .secondary-button,
  .file-button {
    min-height: 48px;
    width: 100%;
  }

  .preview-panel {
    display: none;
  }

  .nav-tab {
    text-align: center;
    min-height: 42px;
    padding: 8px;
  }

  .order-card,
  .order-actions,
  .scan-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .scan-card img,
  .scan-file-icon {
    width: 100%;
    height: 180px;
  }

  .order-actions {
    flex-direction: column;
  }
}

@media print {
  body {
    background: white;
  }

  body > *:not(#printArea) {
    display: none !important;
  }

  #printArea {
    display: block;
  }

  .print-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    color: #111;
    font-family: Arial, sans-serif;
    background: white;
  }

  .print-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18mm 14mm 12mm;
    color: white;
    background: #050505;
    border-bottom: 3mm solid #e30613;
  }

  .print-header img {
    width: 72mm;
  }

  .print-header h1 {
    color: #d8dce1;
    font-size: 30pt;
    text-align: right;
  }

  .print-header p {
    margin: 4mm 0 0;
    color: #e30613;
    font-weight: 900;
    text-align: right;
  }

  .print-content {
    padding: 10mm 14mm 8mm;
  }

  .print-grid {
    display: grid;
    grid-template-columns: 36mm 1fr 32mm 28mm;
    column-gap: 4mm;
    row-gap: 5mm;
    align-items: end;
  }

  .print-label {
    font-weight: 900;
  }

  .print-value {
    min-height: 7mm;
    border-bottom: 0.3mm solid #777;
    white-space: pre-wrap;
  }

  .print-full {
    grid-column: 2 / -1;
  }

  .print-hours {
    width: 100%;
    margin-top: 12mm;
    border-collapse: collapse;
  }

  .print-hours th,
  .print-hours td {
    height: 9mm;
    border: 0.3mm solid #555;
    padding: 2mm;
    text-align: left;
  }

  .print-signature {
    margin-top: 12mm;
    display: grid;
    grid-template-columns: 42mm 1fr;
    gap: 4mm;
    align-items: end;
  }

  .print-signature img {
    max-height: 24mm;
    max-width: 110mm;
  }

  .print-footer {
    margin-top: 15mm;
    padding: 8mm 14mm;
    color: white;
    background: #050505;
    border-top: 3mm solid #e30613;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10mm;
    font-size: 10pt;
  }
}
