*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #e4e4e8;
  --bg-secondary: #d8d8de;
  --surface: #eeeff2;
  --surface-raised: #f4f4f6;
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.1);
  --text: #2c2c2e;
  --text-secondary: #636366;
  --text-tertiary: #8e8e93;
  --primary: #5a7d9a;
  --primary-hover: #4d6d87;
  --danger: #c75050;
  --success: #4a9d62;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.47;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 22px;
}

.auth-card {
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-card h1 {
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 16px;
  text-align: center;
  margin-bottom: 32px;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.app-shell.wide {
  max-width: 1360px;
}

.hidden {
  display: none !important;
}

.page-panel {
  display: none;
}

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

.page-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-bar-left,
.page-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.page-bar h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-meta {
  padding: 20px 18px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.15fr);
  gap: 16px;
  align-items: stretch;
  min-height: 560px;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  min-height: 560px;
  padding: 0;
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.pane-head h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.pane-head .input {
  max-width: 280px;
  flex: 1;
  min-width: 160px;
}

.picker-tall {
  flex: 1;
  max-height: none;
  min-height: 420px;
  border: none;
  border-radius: 0;
  overflow: auto;
}

.selected-head,
.selected-row {
  display: grid;
  grid-template-columns: 1.6fr 0.7fr 88px 110px 100px 40px;
  gap: 10px;
  align-items: center;
}

.selected-head {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.selected-list {
  flex: 1;
  margin-top: 0;
  overflow: auto;
  padding: 10px 16px 16px;
  min-height: 320px;
}

.sticky-summary {
  margin-top: auto;
  border-radius: 0;
  border-top: 1px solid var(--border);
}

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

.brand h1 {
  font-size: 24px;
  font-weight: 600;
}

.brand p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

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

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar .grow {
  flex: 1;
  min-width: 180px;
}

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--surface);
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover td {
  background: rgba(90, 125, 154, 0.06);
}

.muted {
  color: var(--text-tertiary);
  font-size: 13px;
}

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

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea,
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.input:focus {
  outline: none;
  border-color: var(--primary);
}

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

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

.btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

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

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-hover);
  color: #fff;
}

.btn.danger {
  color: var(--danger);
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.form-error {
  color: var(--danger);
  font-size: 14px;
  min-height: 20px;
  margin-top: 12px;
  text-align: center;
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.28);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.modal-card.wide {
  max-width: 920px;
}

.modal-card h3 {
  font-size: 20px;
  margin-bottom: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.picker {
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 240px;
  overflow: auto;
  background: #fff;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
  border: 1.5px dashed var(--border-strong);
  border-radius: 12px;
  padding: 18px 16px;
  text-align: center;
  background: #fff;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  margin-bottom: 12px;
  position: relative;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(90, 125, 154, 0.06);
  color: var(--primary);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.dropzone strong {
  color: var(--text);
  font-weight: 600;
}

.file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 12px;
}

.file-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.picker-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.picker-item:last-child {
  border-bottom: none;
}

.picker-item:hover,
.picker-item.selected {
  background: rgba(90, 125, 154, 0.08);
}

.picker-item input {
  margin-top: 3px;
}

.selected-row {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.selected-row:last-child {
  border-bottom: none;
}

.selected-row .name {
  font-size: 14px;
}

.summary-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.summary-bar strong {
  font-size: 18px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.badge.done {
  background: rgba(74, 157, 98, 0.15);
  color: var(--success);
}

.print-only {
  display: none;
}

@media print {
  body {
    background: #fff;
  }
  .topbar, .tabs, .toolbar, .no-print, .page-bar {
    display: none !important;
  }
  #homeView,
  #panel-quote-edit {
    display: none !important;
  }
  #panel-quote-detail {
    display: block !important;
  }
  .card {
    border: none;
    box-shadow: none;
  }
  .print-only {
    display: block;
  }
}

@media (max-width: 960px) {
  .editor-grid {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .editor-pane {
    min-height: 0;
  }

  .picker-tall {
    min-height: 280px;
    max-height: 360px;
  }

  .selected-list {
    min-height: 200px;
  }
}

@media (max-width: 720px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .selected-head {
    display: none;
  }
  .selected-row {
    grid-template-columns: 1fr 1fr;
  }
  .auth-card {
    padding: 36px 24px;
  }
  .page-bar h2 {
    font-size: 18px;
  }
}
