    :root {
      --bg: #f5f7fa;
      --surface: #ffffff;
      --surface-soft: #eef3f8;
      --text: #17202a;
      --muted: #687789;
      --line: #d9e2ec;
      --accent: #0b63ce;
      --accent-dark: #084d9f;
      --ok: #287d3c;
      --danger: #bf2f24;
      --warn: #966000;
      --focus: #ffbf47;
      --shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
    }

    * {
      box-sizing: border-box;
    }

    html {
      color-scheme: light;
      overflow-x: hidden;
    }

    body {
      margin: 0;
      min-width: 320px;
      overflow-x: hidden;
      background: var(--bg);
      color: var(--text);
      font-family: "Segoe UI", Arial, sans-serif;
      line-height: 1.45;
    }

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

    button {
      border: 0;
      cursor: pointer;
    }

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

    a {
      color: var(--accent);
    }

    .app {
      min-height: 100vh;
      display: grid;
      grid-template-rows: 1fr;
      padding-top: 116px;
    }

    .topbar {
      background: #142033;
      color: #fff;
      border-bottom: 4px solid #d8a22a;
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      z-index: 20;
      box-shadow: 0 6px 18px rgba(17, 24, 39, 0.16);
    }

    .topbar-inner {
      width: min(1500px, 100%);
      margin: 0 auto;
      padding: 18px 12px;
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 18px;
      align-items: center;
    }

    .brand {
      display: flex;
      align-items: center;
      gap: 14px;
      min-width: 0;
    }

    .brand-mark {
      width: 72px;
      height: 42px;
      display: block;
      border: 0;
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.95);
      flex: 0 0 auto;
      padding: 5px;
      object-fit: contain;
    }

    .brand h1 {
      margin: 0;
      font-size: 1.25rem;
      line-height: 1.2;
      letter-spacing: 0;
    }

    .brand p {
      margin: 3px 0 0;
      color: #cfdae7;
      font-size: 0.92rem;
    }

    .status {
      min-height: 36px;
      padding: 8px 12px;
      border: 1px solid rgba(255, 255, 255, 0.24);
      border-radius: 8px;
      color: #eef6ff;
      background: rgba(255, 255, 255, 0.08);
      text-align: right;
      max-width: 420px;
    }

    .status.ok {
      border-color: rgba(111, 220, 142, 0.42);
      color: #dfffea;
    }

    .status.warn {
      border-color: rgba(255, 207, 111, 0.58);
      color: #fff3d6;
    }

    .status.error {
      border-color: rgba(255, 141, 132, 0.62);
      color: #ffe1de;
    }

    main {
      width: min(1500px, 100%);
      margin: 0 auto;
      padding: 12px;
      display: grid;
      gap: 18px;
    }

    .toolbar {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
      align-items: center;
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 12px;
      box-shadow: var(--shadow);
    }

    .toolbar-group {
      display: flex;
      gap: 8px;
      align-items: center;
      flex-wrap: wrap;
    }

    .toolbar-spacer {
      flex: 1 1 auto;
    }

    .button {
      min-height: 38px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      padding: 8px 12px;
      border-radius: 8px;
      border: 1px solid transparent;
      background: var(--accent);
      color: #fff;
      font-weight: 700;
      white-space: nowrap;
    }

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

    .button.secondary {
      background: #fff;
      color: var(--text);
      border-color: var(--line);
    }

    .button.secondary:hover {
      background: var(--surface-soft);
    }

    .button.danger {
      background: var(--danger);
    }

    .button.danger:hover {
      background: #9c2219;
    }

    .button.icon {
      width: 38px;
      padding: 0;
      font-size: 1rem;
    }

    .button.small {
      min-height: 32px;
      padding: 5px 9px;
      font-size: 0.9rem;
    }

    .grid {
      display: grid;
      grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.35fr);
      gap: 18px;
      align-items: start;
    }

    .stack {
      display: grid;
      gap: 18px;
      min-width: 0;
    }

    .panel {
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: var(--shadow);
      overflow: hidden;
      min-width: 0;
    }

    .panel-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
      padding: 14px 16px;
      background: #edf4fb;
      border-bottom: 1px solid var(--line);
    }

    .panel-header h2 {
      margin: 0;
      font-size: 1rem;
      letter-spacing: 0;
    }

    .panel-body {
      padding: 16px;
    }

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

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

    .field.span-2 {
      grid-column: span 2;
    }

    .field.span-4 {
      grid-column: span 4;
    }

    label,
    .label {
      color: #35465a;
      font-size: 0.84rem;
      font-weight: 700;
    }

    input,
    select,
    textarea {
      width: 100%;
      min-height: 38px;
      border: 1px solid #cbd6e2;
      border-radius: 8px;
      padding: 8px 10px;
      background: #fff;
      color: var(--text);
    }

    textarea {
      min-height: 76px;
      resize: vertical;
    }

    input[readonly] {
      background: #edf1f5;
      color: #35465a;
      font-weight: 700;
    }

    input:focus,
    select:focus,
    textarea:focus,
    button:focus-visible,
    summary:focus-visible {
      outline: 3px solid var(--focus);
      outline-offset: 2px;
    }

    [aria-invalid="true"] {
      border-color: var(--danger);
      box-shadow: 0 0 0 1px var(--danger);
    }

    .inline-fields {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 140px auto auto;
      gap: 8px;
      align-items: end;
    }

    .table-wrap {
      overflow-x: auto;
      max-width: 100%;
      min-width: 0;
    }

    table {
      width: 100%;
      border-collapse: collapse;
      min-width: 680px;
    }

    th,
    td {
      padding: 9px 8px;
      border-bottom: 1px solid var(--line);
      vertical-align: top;
      text-align: left;
    }

    th {
      background: #f6f9fc;
      color: #2d4055;
      font-size: 0.82rem;
      text-transform: uppercase;
      letter-spacing: 0;
    }

    tbody tr:nth-child(even) {
      background: #fbfdff;
    }

    td input,
    td select,
    td textarea {
      min-height: 34px;
      padding: 6px 8px;
    }

    td textarea {
      min-height: 42px;
    }

    .col-compact {
      width: 86px;
      min-width: 86px;
    }

    .col-number {
      width: 54px;
      min-width: 54px;
      text-align: center;
    }

    .col-code {
      width: 120px;
      min-width: 120px;
    }

    .col-machine {
      width: 130px;
      min-width: 130px;
    }

    .col-time {
      width: 112px;
      min-width: 112px;
    }

    .col-ref {
      width: 126px;
      min-width: 126px;
    }

    .col-action {
      width: 50px;
      min-width: 50px;
      text-align: center;
    }

    .money {
      text-align: right;
      font-variant-numeric: tabular-nums;
      white-space: nowrap;
    }

    .summary-list {
      display: grid;
      gap: 8px;
    }

    .summary-row {
      display: flex;
      justify-content: space-between;
      gap: 16px;
      padding: 10px 0;
      border-bottom: 1px solid var(--line);
    }

    .summary-row:last-child {
      border-bottom: 0;
    }

    .summary-row strong {
      font-variant-numeric: tabular-nums;
      text-align: right;
      white-space: nowrap;
    }

    .legend {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 8px;
    }

    .legend-item {
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 10px;
      background: #fbfdff;
    }

    .legend-item span {
      display: block;
      color: var(--muted);
      font-size: 0.8rem;
    }

    .signature-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 12px;
    }

    .signature-box {
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fbfdff;
      overflow: hidden;
    }

    .signature-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 8px;
      padding: 8px 10px;
      border-bottom: 1px solid var(--line);
      background: #fff;
    }

    .signature-head h3 {
      margin: 0;
      font-size: 0.92rem;
    }

    canvas {
      display: block;
      width: 100%;
      height: 220px;
      touch-action: none;
      background: #fff;
    }

    .empty-state {
      padding: 14px;
      color: var(--muted);
      font-style: italic;
    }

    .info {
      color: var(--muted);
      font-size: 0.9rem;
    }

    details {
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 12px 14px;
      box-shadow: var(--shadow);
    }

    summary {
      cursor: pointer;
      font-weight: 800;
    }

    .doc-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 14px;
      margin-top: 12px;
    }

    .doc-grid h3 {
      margin: 0 0 6px;
      font-size: 0.95rem;
    }

    .doc-grid p {
      margin: 0;
      color: var(--muted);
      font-size: 0.9rem;
    }

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

    /* Modals & Dialogs */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.72);
      backdrop-filter: blur(4px);
      z-index: 100;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px;
      opacity: 1;
      visibility: visible;
      transition: opacity 0.2s ease, visibility 0.2s ease;
    }

    .modal-overlay.hidden {
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
    }

    .modal-card {
      background: var(--surface);
      border-radius: 12px;
      box-shadow: 0 20px 40px rgba(0, 0, 0, 0.22);
      max-width: 580px;
      width: 100%;
      max-height: 90vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      animation: modalSlideIn 0.22s ease-out;
    }

    .modal-card.fullscreen-signature {
      max-width: 900px;
      width: 95vw;
      height: 82vh;
    }

    @keyframes modalSlideIn {
      from { transform: translateY(16px) scale(0.98); opacity: 0; }
      to { transform: translateY(0) scale(1); opacity: 1; }
    }

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

    .modal-head h2 {
      margin: 0;
      font-size: 1.15rem;
      color: var(--text);
    }

    .modal-body {
      padding: 20px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    .modal-footer {
      padding: 14px 20px;
      border-top: 1px solid var(--line);
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      background: var(--surface-soft);
    }

    .alert-box {
      padding: 12px 14px;
      border-radius: 8px;
      font-size: 0.9rem;
      line-height: 1.4;
    }

    .alert-box.warn {
      background: #fff8e6;
      border: 1px solid #fedc77;
      color: #7b5500;
    }

    .alert-box.danger {
      background: #fdf2f2;
      border: 1px solid #f8b4b4;
      color: #9b1c1c;
    }

    .cleanup-scope-group {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .radio-card {
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 12px 14px;
      background: #fbfdff;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      gap: 8px;
      transition: border-color 0.15s, background 0.15s;
    }

    .radio-card:hover {
      background: #f0f7ff;
      border-color: var(--accent);
    }

    .radio-card-header {
      display: flex;
      align-items: center;
      gap: 10px;
      font-weight: 600;
      font-size: 0.95rem;
    }

    .radio-card input[type="radio"] {
      width: 18px;
      height: 18px;
      cursor: pointer;
    }

    .cleanup-date-fields {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      padding-left: 28px;
    }

    .cleanup-date-fields.single {
      grid-template-columns: 1fr;
    }

    .cleanup-date-fields label {
      font-size: 0.82rem;
      color: var(--muted);
      margin-bottom: 2px;
      display: block;
    }

    .cleanup-preview-box {
      padding: 12px 14px;
      background: var(--surface-soft);
      border-radius: 8px;
      font-size: 0.92rem;
      font-weight: 500;
      color: var(--text);
    }

    .danger-confirm-box {
      display: flex;
      flex-direction: column;
      gap: 6px;
      border-top: 1px solid var(--line);
      padding-top: 14px;
    }

    .danger-confirm-box input {
      border-color: var(--danger);
      font-weight: 700;
      letter-spacing: 1px;
    }

    .danger-text {
      color: var(--danger) !important;
      border-color: rgba(191, 47, 36, 0.4) !important;
    }

    .danger-text:hover {
      background: #fdf2f2 !important;
    }

    .signature-actions {
      display: flex;
      gap: 6px;
    }

    .modal-canvas-wrap {
      flex: 1;
      min-height: 280px;
      border: 1px solid var(--line);
      border-radius: 8px;
      overflow: hidden;
      background: #ffffff;
      position: relative;
    }

    .modal-canvas-wrap canvas {
      width: 100%;
      height: 100%;
      touch-action: none;
      display: block;
      background: #ffffff;
    }

    kbd {
      background: var(--surface-soft);
      border: 1px solid var(--line);
      border-radius: 4px;
      padding: 2px 5px;
      font-size: 0.85em;
      font-family: monospace;
    }

    /* Responsive Media Queries */
    
    /* Cloud Badge & Cloudflare KV Settings */
    .topbar-status-wrap {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .cloud-badge {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      font-size: 0.78rem;
      font-weight: 600;
      padding: 4px 9px;
      border-radius: 12px;
      white-space: nowrap;
      transition: background 0.2s, color 0.2s, border-color 0.2s;
    }

    .cloud-badge.online {
      background: rgba(46, 204, 113, 0.18);
      color: #b3ffce;
      border: 1px solid rgba(46, 204, 113, 0.45);
    }

    .cloud-badge.offline {
      background: rgba(241, 196, 15, 0.18);
      color: #ffeaa7;
      border: 1px solid rgba(241, 196, 15, 0.45);
    }

    .cloud-badge.syncing {
      background: rgba(52, 152, 219, 0.18);
      color: #aed9ff;
      border: 1px solid rgba(52, 152, 219, 0.45);
    }

    .cloud-badge.error {
      background: rgba(231, 76, 60, 0.18);
      color: #ffb8b1;
      border: 1px solid rgba(231, 76, 60, 0.45);
    }

    .cloud-badge.warn {
      background: rgba(230, 126, 34, 0.18);
      color: #ffd1a4;
      border: 1px solid rgba(230, 126, 34, 0.45);
    }

    .cloud-config-form,
    .supabase-config-form {
      display: flex;
      flex-direction: column;
      gap: 8px;
      margin-top: 8px;
      background: var(--surface-soft);
      padding: 12px 14px;
      border-radius: 8px;
      border: 1px solid var(--line);
    }

    .cloud-config-form .field,
    .supabase-config-form .field {
      display: flex;
      flex-direction: column;
      gap: 3px;
    }

    .cloud-config-form label,
    .supabase-config-form label {
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--muted);
    }

    .cloud-config-form input,
    .supabase-config-form input {
      font-size: 0.9rem;
      padding: 6px 10px;
      background: #ffffff;
    }

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

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

      .field.span-4 {
        grid-column: span 2;
      }

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

    @media (max-width: 768px) {
      .app {
        padding-top: 130px;
      }

      .topbar-inner {
        grid-template-columns: 1fr auto;
        padding: 10px 14px;
        gap: 10px;
      }

      .brand {
        gap: 10px;
      }

      .brand-mark {
        width: 50px;
        height: 32px;
        padding: 2px;
      }

      .brand h1 {
        font-size: 1.05rem;
      }

      .brand p {
        display: none;
      }

      .status {
        padding: 6px 10px;
        font-size: 0.8rem;
        min-height: 32px;
      }

      main {
        padding: 12px;
      }

      .toolbar {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
      }

      .toolbar-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
      }

      .toolbar-group.wide {
        grid-template-columns: 1fr;
      }

      .button,
      .archive-select {
        min-height: 44px;
        font-size: 0.92rem;
      }

      .form-grid,
      .inline-fields,
      .legend {
        grid-template-columns: 1fr;
      }

      .field.span-2,
      .field.span-4 {
        grid-column: span 1;
      }

      /* Mobile Table -> Card Transformation */
      .table-wrap {
        overflow-x: visible;
        border: none;
        background: transparent;
      }

      table, thead, tbody, th, td, tr {
        display: block;
      }

      thead {
        display: none;
      }

      tbody tr {
        position: relative;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: 14px;
        margin-bottom: 14px;
        box-shadow: 0 2px 10px rgba(17, 24, 39, 0.05);
        display: flex;
        flex-direction: column;
        gap: 10px;
      }

      td {
        padding: 0;
        border: none;
        display: flex;
        flex-direction: column;
        width: 100% !important;
        min-width: 0 !important;
      }

      td::before {
        content: attr(data-label);
        font-size: 0.76rem;
        font-weight: 700;
        letter-spacing: 0.4px;
        text-transform: uppercase;
        color: var(--muted);
        margin-bottom: 4px;
      }

      td.col-number {
        position: absolute;
        top: 12px;
        left: 14px;
        width: auto !important;
        background: var(--surface-soft);
        color: var(--text);
        font-weight: 700;
        font-size: 0.85rem;
        padding: 3px 10px;
        border-radius: 20px;
        border: 1px solid var(--line);
      }

      td.col-number::before {
        display: none;
      }

      td.col-action {
        position: absolute;
        top: 10px;
        right: 12px;
        width: auto !important;
      }

      td.col-action::before {
        display: none;
      }

      td.col-action .button {
        width: 36px;
        height: 36px;
        min-height: 36px;
        font-size: 1.25rem;
        line-height: 1;
        padding: 0;
        border-radius: 50%;
      }

      td.col-machine,
      td.col-code {
        margin-top: 36px;
      }

      td.money[id^="mat-total-"] {
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--accent);
        background: var(--surface-soft);
        padding: 8px 12px;
        border-radius: 6px;
        text-align: left;
      }

      input,
      select,
      textarea {
        font-size: 16px !important; /* Prevents auto-zoom in iOS Safari */
        min-height: 44px;
      }

      textarea {
        min-height: 64px;
      }

      .cleanup-date-fields {
        grid-template-columns: 1fr;
        padding-left: 0;
      }
    }
  </style>
