:root {
      --bg-color: #090a0f;
      --card-bg: #12151e;
      --panel-bg: #181c27;
      --input-bg: #0f1118;
      --border-color: #262c3d;
      --border-focus: #3b82f6;
      --accent-color: #3b82f6;
      --accent-glow: rgba(59, 130, 246, 0.15);
      --text-main: #f3f4f6;
      --text-muted: #8c96a8;
      --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; font-family: var(--font-main); }

    body {
      background-color: var(--bg-color);
      color: var(--text-main);
      padding: 20px;
      display: flex;
      justify-content: center;
      align-items: flex-start;
      min-height: 100vh;
    }

    .app-container {
      width: 100%;
      max-width: 1150px;
      background: var(--card-bg);
      border: 1px solid var(--border-color);
      border-radius: 12px;
      padding: 24px;
      box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
      display: flex;
      flex-direction: column;
      gap: 20px;
    }

    .app-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid var(--border-color);
      padding-bottom: 14px;
    }

    .app-header h1 {
      font-size: 1.25rem;
      font-weight: 600;
    }

    .app-header h1 span { color: var(--accent-color); }

    .panel {
      background: var(--panel-bg);
      border: 1px solid var(--border-color);
      border-radius: 10px;
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .panel-title {
      font-size: 0.85rem;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--accent-color);
      font-weight: 700;
    }

    .form-row {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
      gap: 10px;
      align-items: end;
    }

    .form-group {
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .form-group label {
      font-size: 0.7rem;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--text-muted);
      font-weight: 600;
    }

    input, select, textarea {
      width: 100%;
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      color: var(--text-main);
      padding: 7px 10px;
      border-radius: 6px;
      font-size: 0.82rem;
      outline: none;
    }

    textarea { resize: vertical; min-height: 56px; }

    input:focus, select:focus, textarea:focus {
      border-color: var(--border-focus);
      box-shadow: 0 0 0 3px var(--accent-glow);
    }

    .btn {
      background: var(--accent-color);
      color: #fff;
      border: none;
      padding: 8px 14px;
      border-radius: 6px;
      font-weight: 600;
      font-size: 0.82rem;
      cursor: pointer;
      transition: background 0.2s;
    }

    .btn:hover { background: #2563eb; }

    .btn-danger {
      background: #ef4444;
      padding: 6px 10px;
      font-size: 0.75rem;
    }

    .btn-danger:hover { background: #dc2626; }

    .color-swatch {
      display: inline-block;
      width: 12px;
      height: 12px;
      border-radius: 3px;
      border: 1px solid var(--border-color);
      margin-right: 6px;
      vertical-align: middle;
    }

    .window-list-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.82rem;
    }

    .window-list-table th, .window-list-table td {
      border-bottom: 1px solid var(--border-color);
      padding: 8px;
      text-align: left;
      vertical-align: middle;
    }

    .window-list-table th { color: var(--text-muted); text-transform: uppercase; font-size: 0.7rem; }

    .thumb-preview {
      width: 45px;
      height: 45px;
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 2px;
    }

    .thumb-preview svg { width: 100%; height: 100%; }

    .cutting-profile-block {
      background: var(--panel-bg);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      padding: 16px;
      margin-bottom: 16px;
    }

    .profile-header {
      display: flex;
      justify-content: space-between;
      margin-bottom: 12px;
      font-size: 0.9rem;
      font-weight: 600;
      gap: 16px;
      flex-wrap: wrap;
    }

    .profile-stats {
      font-size: 0.78rem;
      color: var(--text-muted);
      font-family: var(--font-mono);
      text-align: right;
    }

    .bar-container {
      margin-bottom: 12px;
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      border-radius: 6px;
      padding: 8px;
    }

    .bar-info {
      display: flex;
      justify-content: space-between;
      font-size: 0.75rem;
      margin-bottom: 6px;
      color: var(--text-muted);
      font-family: var(--font-mono);
      gap: 12px;
    }

    .bar-visual {
      display: flex;
      height: 32px;
      background: #000;
      border-radius: 4px;
      overflow: hidden;
      border: 1px solid var(--border-color);
    }

    .cut-piece {
      height: 100%;
      background: #2563eb;
      border-right: 2px solid #ef4444;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.68rem;
      font-family: var(--font-mono);
      color: #fff;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding: 0 2px;
    }

    .waste-piece {
      height: 100%;
      background: #374151;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.68rem;
      color: #9ca3af;
      font-family: var(--font-mono);
    }

    .reusable-piece {
      height: 100%;
      background: #059669;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.68rem;
      font-family: var(--font-mono);
    }

    .panel-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .btn-outline {
      background: transparent;
      border: 1px solid var(--border-color);
      color: var(--text-muted);
    }

    .btn-outline:hover {
      border-color: var(--border-focus);
      color: var(--text-main);
      background: var(--accent-glow);
    }

    .btn-sm {
      padding: 6px 10px;
      font-size: 0.75rem;
    }

    .list-empty {
      color: var(--text-muted);
      font-size: 0.85rem;
      padding: 20px;
      text-align: center;
      border: 1px dashed var(--border-color);
      border-radius: 8px;
    }

    .window-cards {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 14px;
    }

    @media (max-width: 720px) {
      .window-cards { grid-template-columns: 1fr; }
    }

    .window-card {
      background: var(--card-bg);
      border: 1px solid var(--border-color);
      border-radius: 10px;
      overflow: hidden;
      display: flex;
      flex-direction: column;
    }

    .card-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 14px;
      border-bottom: 1px solid var(--border-color);
      font-size: 0.85rem;
    }

    .card-ref {
      color: var(--accent-color);
      font-weight: 700;
    }

    .card-qty {
      background: var(--accent-glow);
      color: var(--accent-color);
      border-radius: 999px;
      padding: 2px 10px;
      font-size: 0.72rem;
      font-weight: 700;
    }

    .card-svg {
      padding: 12px;
      background: var(--input-bg);
      border-bottom: 1px solid var(--border-color);
    }

    .card-svg svg {
      width: 100%;
      height: 130px;
      display: block;
    }

    .card-body {
      padding: 12px 14px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      flex: 1;
    }

    .card-title {
      font-size: 0.95rem;
      font-weight: 700;
    }

    .card-sub {
      font-size: 0.78rem;
      color: var(--text-muted);
    }

    .card-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 6px 14px;
      margin-top: 4px;
    }

    .card-field {
      display: flex;
      flex-direction: column;
      gap: 2px;
    }

    .card-field span {
      font-size: 0.62rem;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--text-muted);
      font-weight: 600;
    }

    .card-field b {
      font-size: 0.8rem;
      font-weight: 600;
    }

    .card-profiles {
      margin-top: 4px;
      border-top: 1px dashed var(--border-color);
      padding-top: 8px;
      font-size: 0.74rem;
      color: var(--text-muted);
      display: flex;
      flex-direction: column;
      gap: 3px;
    }

    .card-profiles b {
      color: var(--text-main);
      font-weight: 600;
    }

    .card-actions {
      display: flex;
      gap: 8px;
      padding: 12px 14px;
      border-top: 1px solid var(--border-color);
    }

    .card-actions .btn {
      flex: 1;
    }

    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(2px);
      align-items: flex-start;
      justify-content: center;
      padding: 40px 16px;
      z-index: 1000;
      overflow-y: auto;
    }

    .modal {
      background: var(--card-bg);
      border: 1px solid var(--border-color);
      border-radius: 12px;
      width: 100%;
      max-width: 720px;
      box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
      display: flex;
      flex-direction: column;
      gap: 16px;
      padding: 20px;
    }

    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .modal-close {
      background: transparent;
      border: none;
      color: var(--text-muted);
      font-size: 1.3rem;
      cursor: pointer;
      line-height: 1;
      padding: 2px 6px;
      border-radius: 4px;
    }

    .modal-close:hover {
      color: var(--text-main);
      background: var(--panel-bg);
    }

    .modal-footer {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
    }

    .price-input {
      width: 90px;
      padding: 5px 8px;
    }

    .material-table td { white-space: nowrap; }

    .form-group.is-idle { display: none; }

    .login-screen {
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
    }

    .login-card {
      width: 100%;
      max-width: 380px;
      background: var(--card-bg);
      border: 1px solid var(--border-color);
      border-radius: 12px;
      padding: 28px;
      display: flex;
      flex-direction: column;
      gap: 14px;
    }

    .login-error {
      display: none;
      color: #fecaca;
      background: rgba(239, 68, 68, 0.15);
      border: 1px solid #ef4444;
      border-radius: 6px;
      padding: 8px 10px;
      font-size: 0.82rem;
    }

    .header-meta {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      justify-content: flex-end;
    }

    .header-meta select { width: auto; min-width: 180px; }

    .user-label {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      color: var(--text-muted);
    }

    .save-status {
      font-size: 0.72rem;
      color: var(--text-muted);
      min-width: 90px;
    }

    .import-report {
      font-size: 0.78rem;
      color: var(--text-muted);
    }

    .app-container.is-admin { max-width: 1400px; }

    .admin-hint {
      font-size: 0.8rem;
      color: var(--text-muted);
      line-height: 1.45;
    }

    .admin-tabs {
      display: flex;
      gap: 6px;
      flex-wrap: wrap;
    }

    .admin-tab {
      background: transparent;
      border: 1px solid var(--border-color);
      color: var(--text-muted);
      border-radius: 6px;
      padding: 6px 12px;
      font-size: 0.78rem;
      cursor: pointer;
    }

    .admin-tab.is-active {
      border-color: var(--accent-color);
      color: var(--text-main);
      background: var(--accent-glow);
    }

    .admin-toolbar {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: center;
    }

    .admin-file {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      font-size: 0.78rem;
      color: var(--text-muted);
      cursor: pointer;
    }

    .admin-file input {
      max-width: 220px;
      font-size: 0.75rem;
    }

    .admin-columns-help {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      color: var(--text-muted);
      background: var(--input-bg);
      border: 1px dashed var(--border-color);
      border-radius: 6px;
      padding: 8px 10px;
      overflow-x: auto;
      white-space: nowrap;
    }

    .admin-section-label {
      font-size: 0.75rem;
      font-weight: 600;
      color: var(--text-main);
    }

    .admin-table-scroll {
      overflow: auto;
      max-height: 380px;
      border: 1px solid var(--border-color);
      border-radius: 8px;
      background: var(--input-bg);
    }

    .admin-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.72rem;
      font-family: var(--font-mono);
      table-layout: fixed;
    }

    .admin-table th,
    .admin-table td {
      border-bottom: 1px solid var(--border-color);
      border-right: 1px solid var(--border-color);
      padding: 4px 6px;
      text-align: left;
      vertical-align: middle;
      white-space: nowrap;
      overflow: hidden;
    }

    .admin-table th {
      position: sticky;
      top: 0;
      background: #1c2230;
      color: var(--accent-color);
      z-index: 1;
      font-weight: 600;
      font-size: 0.72rem;
      line-height: 1.2;
    }

    .admin-table tr.is-error { background: rgba(239, 68, 68, 0.16); }
    .admin-table tr.is-create { background: rgba(16, 185, 129, 0.08); }
    .admin-table tr.is-update { background: rgba(59, 130, 246, 0.1); }

    .admin-table-edit .admin-cell-input,
    .admin-table-edit select.admin-cell-input {
      width: 100%;
      min-width: 0;
      max-width: none;
      background: transparent;
      border: 1px solid transparent;
      color: inherit;
      font: inherit;
      padding: 2px 4px;
      border-radius: 4px;
      box-sizing: border-box;
    }

    .admin-table-edit .admin-cell-input:focus {
      border-color: var(--accent-color);
      background: var(--card-bg);
      outline: none;
    }

    .admin-hex-cell {
      display: flex;
      align-items: center;
      gap: 4px;
      min-width: 0;
    }

    .admin-hex-cell .admin-cell-input { flex: 1; }

    .admin-hex-pick {
      width: 18px;
      height: 18px;
      padding: 0;
      border: 1px solid var(--border-color);
      background: transparent;
      cursor: pointer;
      flex: 0 0 18px;
    }

    .admin-row-del {
      background: transparent;
      border: 0;
      color: var(--text-muted);
      cursor: pointer;
      font-size: 1rem;
      line-height: 1;
      padding: 2px 4px;
    }

    .admin-row-del:hover { color: #fecaca; }

    .admin-table th.admin-col-del,
    .admin-table td.admin-col-del {
      width: 24px;
      min-width: 24px;
      max-width: 24px;
      text-align: center;
      position: sticky;
      left: 0;
      background: #1c2230;
      z-index: 2;
      padding: 3px 2px;
    }

    .admin-table tbody td.admin-col-del { background: var(--input-bg); }
    .admin-table tbody tr.is-error td.admin-col-del { background: #2a1518; }

    .admin-note-row td {
      white-space: normal;
      padding: 2px 6px 6px 6px;
      border-top: 0;
    }

    .admin-cell-msg {
      display: block;
      color: #fecaca;
      font-size: 0.68rem;
      white-space: normal;
    }

    .admin-cell-warn {
      display: block;
      color: #fcd34d;
      font-size: 0.68rem;
      white-space: normal;
    }

    .admin-swatch {
      display: inline-block;
      width: 12px;
      height: 12px;
      border-radius: 3px;
      border: 1px solid var(--border-color);
      vertical-align: middle;
      margin-right: 6px;
    }

    .admin-issues {
      font-size: 0.78rem;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .admin-issues .is-error { color: #fecaca; }
    .admin-issues .is-warn { color: #fcd34d; }

    .admin-confirm-row {
      display: flex;
      justify-content: flex-end;
      gap: 8px;
    }

    .admin-preview-wrap {
      display: flex;
      flex-direction: column;
      gap: 8px;
      padding-top: 4px;
      border-top: 1px dashed var(--border-color);
    }

    .admin-preview-wrap[hidden] { display: none; }

    #app-root { display: none; }
