:root {
  --bg: #f4faff;
  --card: #ffffff;
  --line: #d9ecf7;
  --primary: #39a9e8;
  --primary-dark: #1683bd;
  --primary-pale: #e8f7ff;
  --text: #334155;
  --muted: #64748b;
  --danger: #d9534f;
  --warning-bg: #fff8df;
  --danger-bg: #fff0f0;
  --success-bg: #ecfbf4;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(65, 139, 177, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic",
    "Hiragino Kaku Gothic ProN", sans-serif;
}

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

button { touch-action: manipulation; }

.app-header {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
}

h1, h2, p { margin-top: 0; }

h1 { margin-bottom: 0; font-size: 26px; }

h2 { margin: 0; font-size: 20px; }

.connection-status {
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--primary-pale);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}

.connection-status.error {
  background: var(--danger-bg);
  color: var(--danger);
}

.tabs {
  max-width: 1120px;
  margin: 0 auto 18px;
  padding: 0 20px;
  display: flex;
  gap: 8px;
}

.tab-button {
  min-width: 130px;
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

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

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

.view { display: none; }
.view.active { display: block; }

.card {
  margin-bottom: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.section-heading {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-heading > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.step-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-pale);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > span,
.quick-note-group > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.full-width { grid-column: 1 / -1; }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #cbdfea;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(57, 169, 232, .14);
}

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.quick-buttons button,
.text-button,
.secondary-button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--primary-pale);
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
}

.choice-button {
  min-height: 56px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.choice-button.active {
  border-color: var(--primary);
  background: var(--primary-pale);
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.price-panel {
  margin-top: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 12px;
  background: #f8fcff;
}

.price-panel div {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.price-panel strong { font-size: 21px; color: var(--primary-dark); }
.price-panel small { color: var(--muted); }

.segmented-control {
  width: fit-content;
  margin-bottom: 16px;
  padding: 4px;
  display: flex;
  border-radius: 11px;
  background: #edf6fb;
}

.segmented-control button {
  padding: 9px 20px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.segmented-control button.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(45, 111, 148, .12);
}

.tooth-chart {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.quadrant {
  padding: 14px;
  background: #fbfdff;
}

.quadrant:nth-child(odd) { border-right: 1px solid var(--line); }
.quadrant:nth-child(-n+2) { border-bottom: 1px solid var(--line); }

.quadrant-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.teeth-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.tooth-button {
  width: 40px;
  height: 48px;
  padding: 0;
  border: 1px solid #c9e1ee;
  border-radius: 12px 12px 16px 16px;
  background: #fff;
  color: #416174;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
}

.tooth-button.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 5px 12px rgba(57, 169, 232, .24);
}

.selected-teeth {
  margin-top: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 11px;
  background: var(--primary-pale);
}

.selected-teeth span { color: var(--muted); font-size: 13px; }
.selected-teeth strong { flex: 1; color: var(--primary-dark); }

.shade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 8px;
}

.shade-button {
  padding: 11px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

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

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  width: 48px;
  height: 27px;
  position: relative;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #cbd5e1;
  transition: .2s;
}

.switch::after {
  content: "";
  width: 21px;
  height: 21px;
  position: absolute;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
  box-shadow: 0 2px 5px rgba(0,0,0,.15);
}

.switch-row input:checked + .switch { background: var(--primary); }
.switch-row input:checked + .switch::after { transform: translateX(21px); }

.switch-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.metal-panel {
  margin-top: 18px;
  padding-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  border-top: 1px solid var(--line);
}

.number-stepper {
  min-height: 44px;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  border: 1px solid #cbdfea;
  border-radius: 10px;
  overflow: hidden;
}

.number-stepper button {
  min-width: 54px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--primary-pale);
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 800;
}

.number-stepper button:nth-last-child(-n+2) {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.number-stepper output {
  display: grid;
  place-items: center;
  background: #fff;
  font-weight: 800;
}

.quick-note-group + .quick-note-group { margin-top: 18px; }
.quick-note-group textarea { margin-top: 8px; }

.summary-bar {
  position: sticky;
  bottom: 14px;
  z-index: 5;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 12px 30px rgba(55, 125, 161, .15);
  backdrop-filter: blur(8px);
}

.summary-bar span, .summary-bar small {
  display: block;
  color: var(--muted);
}

.summary-bar strong {
  font-size: 24px;
  color: var(--primary-dark);
}

.primary-button {
  min-width: 180px;
  padding: 14px 24px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 7px 16px rgba(57, 169, 232, .25);
}

.primary-button:disabled { opacity: .55; cursor: wait; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-header p { margin: 6px 0 0; color: var(--muted); }

.status-filters {
  margin: 18px 0 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-button {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

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

.list-controls {
  margin-bottom: 14px;
  display: flex;
  justify-content: flex-end;
}

.list-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-controls span { color: var(--muted); font-size: 13px; }
.list-controls select { width: auto; }

.order-list {
  display: grid;
  gap: 10px;
}

.order-card {
  padding: 16px;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr) 190px;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.order-card.overdue { background: var(--danger-bg); }
.order-card.soon { background: var(--warning-bg); }

.order-date {
  text-align: center;
}

.order-date strong {
  display: block;
  color: var(--primary-dark);
  font-size: 18px;
}

.order-date span {
  color: var(--muted);
  font-size: 12px;
}

.order-main { min-width: 0; }

.order-main h3 {
  margin: 0 0 7px;
  font-size: 17px;
}

.order-main p {
  margin: 3px 0;
  color: var(--muted);
  font-size: 13px;
}

.order-main .prosthetic {
  color: var(--text);
  font-weight: 700;
}

.status-editor {
  display: flex;
  gap: 7px;
}

.status-editor select { min-width: 0; }

.status-editor button {
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.status-badge {
  display: inline-block;
  margin-bottom: 8px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--primary-pale);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.empty-state {
  padding: 50px 20px;
  border: 1px dashed #bad9e9;
  border-radius: 13px;
  color: var(--muted);
  text-align: center;
}

.toast {
  max-width: calc(100% - 32px);
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  padding: 13px 17px;
  border-radius: 11px;
  background: #263746;
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .2s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #b63d3d; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  gap: 10px;
  background: rgba(244, 250, 255, .72);
  color: var(--primary-dark);
  font-weight: 800;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: auto;
  border: 4px solid #d9edf7;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

@media (max-width: 760px) {
  .app-header { align-items: flex-start; }
  h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .section-heading { display: block; }
  .section-heading p { margin: 8px 0 0 38px; }
  .metal-panel { grid-template-columns: 1fr; }
  .order-card { grid-template-columns: 85px 1fr; }
  .status-editor { grid-column: 1 / -1; }
  .summary-bar { align-items: stretch; }
}

@media (max-width: 520px) {
  .card { padding: 18px; }
  .tabs { overflow-x: auto; }
  .tab-button { min-width: 120px; }
  .quadrant { padding: 10px 6px; }
  .teeth-row { gap: 3px; }
  .tooth-button {
    width: 31px;
    height: 43px;
    border-radius: 9px 9px 12px 12px;
  }
  .selected-teeth { flex-wrap: wrap; }
  .summary-bar { position: static; flex-direction: column; }
  .primary-button { width: 100%; }
  .number-stepper button { min-width: 43px; font-size: 12px; }
}


.auth-screen {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, #e7f7ff 0, transparent 42%),
    var(--bg);
}

.auth-card {
  width: min(430px, 100%);
  padding: 34px;
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(50, 126, 165, .13);
}

.auth-card h1 {
  margin: -8px 0 0;
  text-align: center;
}

.auth-card .eyebrow {
  text-align: center;
}

.auth-description {
  margin: -8px 0 4px;
  color: var(--muted);
  text-align: center;
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

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

.current-user {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.current-user small {
  display: block;
  color: var(--muted);
  font-weight: 500;
}

.password-dialog {
  width: min(470px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(35, 86, 112, .25);
}

.password-dialog::backdrop {
  background: rgba(32, 54, 68, .46);
  backdrop-filter: blur(3px);
}

.password-dialog form {
  padding: 26px;
  display: grid;
  gap: 17px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.dialog-heading p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--primary-pale);
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 22px;
}

@media (max-width: 760px) {
  .app-header {
    flex-direction: column;
  }

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

  .current-user {
    width: 100%;
  }
}

.choice-button {
  white-space: normal;
  line-height: 1.35;
}
