:root {
  --brand: #0e7490;
  --brand-dark: #155e75;
  --brand-soft: #ecfeff;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 24px; padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.brand svg { width: 30px; height: 30px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--brand-soft); color: var(--brand-dark); }
.topbar .right { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 13px; color: var(--muted); text-align: right; line-height: 1.2; }
.user-chip strong { color: var(--text); display: block; }

/* Bell */
.bell-wrap { position: relative; }
.icon-btn {
  position: relative; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 20px; height: 20px; }
.count {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.count:empty { display: none; }
.bell-wrap.ring .icon-btn svg { animation: ring .9s ease-in-out 2; transform-origin: 50% 10%; }
@keyframes ring { 0%,100% { transform: rotate(0) } 20% { transform: rotate(18deg) } 40% { transform: rotate(-16deg) } 60% { transform: rotate(10deg) } 80% { transform: rotate(-6deg) } }
.dropdown {
  position: absolute; right: 0; top: 48px; width: 360px; max-height: 70vh; overflow: auto; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(15,23,42,.15);
}
.dropdown header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.notif { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.notif:hover { background: var(--bg); }
.notif.unread { background: var(--brand-soft); }
.notif .t { font-weight: 600; font-size: 14px; }
.notif .b { font-size: 13px; color: var(--muted); }
.notif .d { font-size: 11px; color: var(--muted); margin-top: 2px; }
.dropdown .empty { padding: 24px; text-align: center; color: var(--muted); }
.dropdown footer { padding: 10px 14px; font-size: 12px; color: var(--muted); }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.detail-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .detail-layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .user-chip { display: none; }
}

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14,116,144,.25); border-color: var(--brand); }
textarea { min-height: 96px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--brand); background: var(--brand);
  color: #fff; font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 8px; cursor: pointer; text-decoration: none !important;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.error-box { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }

/* Auth */
.auth-wrap { min-height: calc(100vh - 80px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 440px; }
.auth-card.wide { max-width: 620px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-logo svg { width: 44px; height: 44px; }
.auth-logo div { font-size: 22px; font-weight: 700; line-height: 1.1; }
.auth-logo small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }

.role-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.role-switch button { border: 0; background: transparent; padding: 9px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.role-switch button.active { background: #fff; color: var(--brand-dark); box-shadow: 0 1px 3px rgba(15,23,42,.12); }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #e2e8f0; color: #334155; }
.st-recibido { background: #e0f2fe; color: #075985; }
.st-cotizado { background: #fef3c7; color: #92400e; }
.st-en_diseno { background: #ede9fe; color: #5b21b6; }
.st-en_fabricacion { background: #ffedd5; color: #9a3412; }
.st-control_calidad { background: #fce7f3; color: #9d174d; }
.st-enviado { background: #dbeafe; color: #1e40af; }
.st-entregado { background: #dcfce7; color: #166534; }
.st-cancelado { background: #fee2e2; color: #991b1b; }
.badge.urgent { background: #fee2e2; color: #991b1b; }

/* Stepper */
.stepper { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 4px 0; }
.step { text-align: center; font-size: 11px; color: var(--muted); }
.step .bar { height: 6px; border-radius: 3px; background: var(--line); margin-bottom: 6px; }
.step.done .bar { background: var(--brand); }
.step.current { color: var(--brand-dark); font-weight: 700; }
.step.current .bar { box-shadow: 0 0 0 3px rgba(14,116,144,.2); }
.mini-progress { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 10px; }
.mini-progress span { display: block; height: 100%; background: var(--brand); }
@media (max-width: 640px) { .step span { display: none; } }

/* Stats */
.stat { padding: 16px 18px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 13px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: #f8fafc; }
.num { text-align: right; white-space: nowrap; }

/* Filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.filters input[type=search] { max-width: 280px; margin-left: auto; }

/* Order cards (client) */
.order-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.order-card { cursor: pointer; transition: transform .1s, box-shadow .1s; }
.order-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15,23,42,.08); }
.order-card .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.order-card .code { font-weight: 700; }
.order-card .meta { font-size: 13px; color: var(--muted); }
.empty-state { text-align: center; padding: 48px 20px; }

/* Definition list */
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.pre { white-space: pre-wrap; }

/* Price */
.price-box { background: var(--brand-soft); border-radius: 10px; padding: 14px 16px; }
.price-box .row { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.price-box .row.total { font-size: 18px; font-weight: 700; border-top: 1px solid #a5f3fc; margin-top: 6px; padding-top: 8px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--brand); }
.timeline .t { font-weight: 600; font-size: 14px; }
.timeline .m { font-size: 14px; white-space: pre-wrap; margin-top: 2px; }
.timeline .d { font-size: 12px; color: var(--muted); }

/* Files */
.files { list-style: none; margin: 0 0 12px; padding: 0; }
.files li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.files li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropzone {
  border: 2px dashed #cbd5e1; border-radius: 10px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; background: #f8fafc;
}
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }
.dropzone strong { color: var(--brand); }
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 10px; }
.progress span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* Odontogram */
.odontogram { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; }
.arch { display: flex; justify-content: center; gap: 4px; min-width: 560px; }
.arch + .arch { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #cbd5e1; }
.arch .mid { width: 2px; background: #cbd5e1; margin: 0 6px; }
.tooth {
  width: 32px; height: 40px; border: 1px solid #cbd5e1; background: #fff; border-radius: 8px 8px 12px 12px; cursor: pointer;
  font-size: 11px; font-weight: 600; color: var(--muted); display: grid; place-items: center; padding: 0;
}
.arch.lower .tooth { border-radius: 12px 12px 8px 8px; }
.tooth:hover { border-color: var(--brand); color: var(--brand); }
.tooth.sel { background: var(--brand); border-color: var(--brand); color: #fff; }
.odo-foot { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--muted); }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 10px; z-index: 50; max-width: 380px; }
.toast { background: #0f172a; color: #fff; border-radius: 10px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 14px; animation: slide .25s ease-out; cursor: pointer; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast .t { font-weight: 700; }
.toast .b { opacity: .85; font-size: 13px; }
@keyframes slide { from { transform: translateY(12px); opacity: 0 } to { transform: none; opacity: 1 } }

/* Email preview */
.email-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.notice { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }

/* Clientes: tabla + panel de edición */
.client-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .client-layout { grid-template-columns: 1fr; } }
