:root {
  --primary: #ff7a1a;
  --primary-dark: #e8630a;
  --primary-darker: #b94c06;
  --primary-light: #ff9c4d;
  --primary-lighter: #ffb877;
  --primary-pale: #fff1e2;
  --accent: #ffcf9e;
  --red: #c0293a;
  --dark: #201f22;
  --muted: #6b6f76;
  --border: #e3e4e7;
  --bg: #eef0f2;
  --gray-1: #fbfbfc;
  --gray-2: #eceded;
  --gray-3: #d9dadd;
  --gray-4: #46474c;
  --gray-5: #29292c;
}

* { box-sizing: border-box; }

input[type=checkbox], input[type=radio] { accent-color: var(--primary); }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--gray-1), var(--bg) 60%, var(--bg));
  background-attachment: fixed;
  color: var(--dark);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { color: var(--primary-darker); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

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

.topbar {
  background: linear-gradient(90deg, var(--gray-5), var(--gray-4) 55%, #313136);
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  border-bottom: 2px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.brand {
  color: white;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.brand-mark {
  display: inline-flex;
  height: 2.1rem;
  width: auto;
  flex-shrink: 0;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.topbar nav a, .topbar nav .link-button {
  color: rgba(255, 255, 255, 0.92);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.topbar nav a:hover, .topbar nav .link-button:hover {
  background: rgba(255, 122, 26, 0.18);
  border-color: rgba(255, 122, 26, 0.45);
  color: var(--primary-light);
}

.inline-form { display: inline; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.messages { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.message {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  border: 1px solid transparent;
}
.message.success { background: #e3f6ec; color: #146c43; border-color: #bfe6d2; }
.message.error { background: #fde3e3; color: #9c1c1c; border-color: #f5c2c2; }
.message.warning { background: #fff3cd; color: #85670a; border-color: #f5e2a3; }

.login-logo {
  display: block;
  height: 4.5rem;
  width: auto;
  margin: 0 auto 1.5rem;
}

.login-card {
  max-width: 380px;
  margin: 3rem auto;
  background: linear-gradient(180deg, #ffffff, var(--gray-1));
  padding: 2.25rem 2rem;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  text-align: center;
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
}
.login-card h1 { margin-top: 0; }
.login-card p { color: var(--muted); font-size: 0.92rem; }
.login-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.1rem;
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-pale);
}

.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--gray-3);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--gray-2), var(--gray-3));
  color: var(--dark);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #ffffff, var(--gray-2));
  border-color: var(--primary);
  color: var(--primary-darker);
  box-shadow: 0 2px 8px rgba(255, 122, 26, 0.25);
}
.btn-secondary {
  background: linear-gradient(180deg, #ffffff, var(--gray-1));
  color: var(--dark);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--primary-light); color: var(--primary-dark); }

fieldset {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.35rem 1.35rem 1.1rem;
  margin-bottom: 1.35rem;
  box-shadow: 0 1px 3px rgba(20, 20, 22, 0.05);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
fieldset:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 4px 14px rgba(20, 20, 22, 0.1);
}
legend {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary-dark);
  padding: 0 0.5rem;
}
legend::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
}

.field { margin-bottom: 0.9rem; }
.field label, .radio-label { display: block; font-weight: 600; margin-bottom: 0.3rem; font-size: 0.9rem; color: var(--dark); }
.field input[type=text], .field input[type=number], .field input[type=date], .field select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field select { cursor: pointer; }
.field input[type=text]:focus, .field input[type=number]:focus, .field input[type=date]:focus,
.field select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-pale);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.hint { color: var(--muted); font-size: 0.85rem; margin-top: -0.25rem; }

.teeth-quadrants {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.tooth-quadrant {
  display: grid;
  grid-template-columns: repeat(8, minmax(1.9rem, 1fr));
  gap: 0.3rem 0.35rem;
}
.tooth-quadrant + .tooth-quadrant {
  border-top: 1px dashed var(--border);
  padding-top: 0.6rem;
}
@media (max-width: 480px) {
  .tooth-quadrant { grid-template-columns: repeat(4, minmax(1.8rem, 1fr)); }
}
.tooth {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  font-size: 0.8rem;
  gap: 0.15rem;
  font-weight: 400;
}

.teeth-cards-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.35rem;
}
@media (max-width: 760px) {
  .teeth-cards-row { grid-template-columns: 1fr; }
}

.teeth-card { text-align: center; margin-bottom: 0; }
.teeth-card .hint { text-align: left; }
.teeth-card .illustration-frame {
  background: var(--primary-pale);
  border-radius: 10px;
  padding: 1rem 0.5rem;
  margin-bottom: 0.75rem;
}
.chart-illustration {
  display: block;
  margin: 0 auto;
  height: 8rem;
  width: auto;
  max-width: 100%;
}

ul { list-style: none; padding: 0; margin: 0; }
ul li { display: inline-block; margin-right: 1.25rem; font-weight: 400; }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem 1rem;
}
@media (min-width: 640px) {
  .checkbox-grid { grid-template-columns: repeat(4, 1fr); }
}
.check-item { font-weight: 400; display: flex; align-items: center; gap: 0.4rem; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(20, 20, 22, 0.05);
  border: 1px solid var(--border);
}
.table th, .table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.table th {
  background: var(--primary-pale);
  color: var(--primary-darker);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.table tbody tr:hover { background: #f8fbfd; }
.table tbody tr:last-child td { border-bottom: none; }
.table a { text-decoration: none; font-weight: 600; }
.table a:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-pending { background: #fff3cd; color: #85670a; }
.badge-synced { background: #d8f0ea; color: #0f6b5c; }
.badge-error { background: #fde3e3; color: #9c1c1c; }

/* --- Órdenes: cards + barra de progreso --- */

.orders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.order-card {
  display: block;
  background: white;
  border-radius: 14px;
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(20, 20, 22, 0.05);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
}
.order-card:hover {
  box-shadow: 0 8px 20px rgba(20, 20, 22, 0.12);
  border-color: var(--primary-light);
}

.order-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.order-card-folio {
  font-weight: 700;
  color: var(--primary-darker);
  font-size: 1.05rem;
}
.order-card-fecha { color: var(--muted); font-size: 0.85rem; }

.order-card dl {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
}
.order-card dl div { display: flex; gap: 0.4rem; padding: 0.1rem 0; }
.order-card dl dt { color: var(--muted); flex: 0 0 auto; }
.order-card dl dd { margin: 0; font-weight: 600; }

.order-card-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  gap: 0.5rem;
}

.progress-track {
  width: 100%;
  height: 0.5rem;
  background: var(--primary-pale);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  transition: width 0.2s ease;
}
.progress-fill.progress-complete {
  background: linear-gradient(90deg, #3fb87f, #0f6b5c);
}
.progress-percent-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-dark);
  white-space: nowrap;
}

.badge-stage { background: var(--primary-pale); color: var(--primary-darker); }
.badge-invoiced { background: #d8f0ea; color: #0f6b5c; }

.order-card-error {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: #9c1c1c;
}

.detail-list {
  background: white;
  border-radius: 12px;
  padding: 1.1rem 1.35rem;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(20, 20, 22, 0.05);
}
.detail-list dt { font-weight: 700; margin-top: 0.6rem; color: var(--primary-dark); }
.detail-list dd { margin: 0.1rem 0 0; }

.odoo-box {
  background: white;
  border-radius: 12px;
  padding: 1.1rem 1.35rem;
  margin-top: 1rem;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(20, 20, 22, 0.05);
}

.attachment-list { list-style: none; padding: 0; margin: 0; }
.attachment-item {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.attachment-item:last-child { border-bottom: none; }
.attachment-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

.attachment-preview {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--gray-1);
}
.attachment-preview iframe {
  display: block;
  width: 100%;
  height: 420px;
  border: 0;
}
.mesh-viewer {
  position: relative;
  width: 100%;
  height: 420px;
}
.mesh-viewer canvas { display: block; touch-action: none; }
.mesh-viewer-hint {
  position: absolute;
  bottom: 0.6rem;
  left: 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.85);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  pointer-events: none;
}

/* Standalone full-page attachment preview (panel/attachment_preview.html) */
.preview-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.preview-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  background: white;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(20, 20, 22, 0.05);
}
.preview-page-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.preview-page-title img { height: 1.8rem; width: auto; flex-shrink: 0; }
.preview-page-filename {
  font-weight: 700;
  color: var(--dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-page-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.preview-stage {
  flex: 1;
  min-height: 0;
  background: var(--gray-1);
}
.preview-stage .mesh-viewer,
.preview-stage iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.file-input {
  display: block;
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px dashed var(--primary-light);
  border-radius: 8px;
  background: var(--primary-pale);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}
.link-button.danger { color: var(--red); }

.field-error { color: #9c1c1c; font-size: 0.85rem; }

.errorlist {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  color: #9c1c1c;
  font-size: 0.85rem;
}
.errorlist li::before { content: "⚠ "; }

.form-errors {
  background: #fde3e3;
  color: #9c1c1c;
  border: 1px solid #f5c2c2;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}
