:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #647084;
  --line: #d7dde8;
  --panel: #ffffff;
  --bg: #f5f7fb;
  --soft: #eef5f2;
  --brand: #0d766e;
  --brand-dark: #075e59;
  --accent: #9f4f2f;
  --warn: #b47b14;
  --done: #286846;
  --shadow: 0 18px 45px rgba(29, 36, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-loading .topbar,
.auth-loading .shell,
.logged-out .topbar,
.logged-out .shell {
  display: none;
}

.login-screen {
  background: linear-gradient(135deg, #17212f 0%, #20413f 55%, #f5f7fb 55%);
  display: none;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.auth-loading .login-screen,
.logged-out .login-screen {
  display: grid;
}

.login-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 410px;
  padding: 24px;
  width: min(100%, 410px);
}

.login-card h1 {
  font-size: 1.6rem;
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0;
}

.form-error {
  color: #a83220;
  font-size: 0.9rem;
  font-weight: 750;
  min-height: 20px;
  margin: 0;
}

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

button {
  cursor: pointer;
}

.topbar {
  align-items: center;
  background: #17212f;
  color: white;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 42px);
}

.topbar h1,
.panel h2,
.dialog-card h2 {
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.45rem, 2.8vw, 2.3rem);
}

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

.user-chip {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: #d9e5f5;
  font-size: 0.86rem;
  font-weight: 800;
  min-height: 34px;
  padding: 7px 11px;
}

.eyebrow {
  color: #718096;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #9fb0c7;
}

.shell {
  padding: 22px clamp(14px, 3vw, 34px) 34px;
}

.hidden {
  display: none !important;
}

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metrics article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metrics span {
  display: block;
  font-size: 2rem;
  font-weight: 850;
}

.metrics p {
  color: var(--muted);
  margin: 4px 0 0;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  align-items: start;
}

.panel,
.dialog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 18px;
  position: sticky;
  top: 14px;
}

.panel-header {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header.compact {
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 16px;
}

.panel h2,
.dialog-card h2 {
  font-size: 1.15rem;
}

form,
.dialog-grid section {
  display: grid;
  gap: 12px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 750;
}

input,
textarea,
select {
  background: #fbfcfe;
  border: 1px solid #c9d1df;
  border-radius: 7px;
  color: var(--ink);
  min-height: 42px;
  outline: none;
  padding: 10px 11px;
  width: 100%;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13, 118, 110, 0.14);
}

.two-col {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.mode-switch {
  background: #edf1f7;
  border: 1px solid #d9e0ea;
  border-radius: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 168px;
  padding: 3px;
}

.mode-switch button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  min-height: 34px;
  padding: 0 10px;
}

.mode-switch button.active {
  background: white;
  color: var(--brand-dark);
  box-shadow: 0 2px 8px rgba(29, 36, 51, 0.08);
}

.primary,
.secondary,
.icon-button {
  align-items: center;
  border-radius: 7px;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
}

.primary {
  background: var(--brand);
  border: 1px solid var(--brand);
  color: white;
}

.primary:hover {
  background: var(--brand-dark);
}

.secondary {
  background: #ffffff;
  border: 1px solid #c8d1df;
  color: var(--ink);
}

.icon-button {
  aspect-ratio: 1;
  background: #ffffff;
  border: 1px solid #c8d1df;
  color: var(--ink);
  font-size: 1.15rem;
  min-width: 42px;
  padding: 0;
}

.topbar .secondary,
.topbar .icon-button {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  color: white;
}

.board {
  display: grid;
  gap: 18px;
}

.admin-section {
  margin-top: 18px;
}

.users-layout,
.clients-layout {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  padding: 14px;
}

.user-form {
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.users-list,
.clients-list {
  display: grid;
  gap: 10px;
}

.client-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.client-card header {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.client-card h3 {
  font-size: 1rem;
  letter-spacing: 0;
  margin: 0 0 4px;
}

.equipment-list {
  display: grid;
  gap: 8px;
}

.equipment-item {
  align-items: center;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: space-between;
  padding: 10px;
}

.equipment-form {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(150px, 1fr) minmax(110px, 0.7fr) auto;
}

.user-card {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 180px 120px auto;
  padding: 14px;
}

.user-card strong {
  overflow-wrap: anywhere;
}

.user-card small {
  color: var(--muted);
  display: block;
  font-weight: 750;
  margin-top: 3px;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.inline-input {
  min-height: 38px;
  padding: 8px 10px;
}

.check-row {
  align-items: center;
  display: flex;
  gap: 8px;
}

.check-row input {
  min-height: auto;
  width: auto;
}

.search {
  max-width: 330px;
}

.schedule-list,
.orders-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.schedule-card,
.order-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.schedule-card {
  align-items: center;
  grid-template-columns: 92px minmax(0, 1fr) auto;
}

.date-pill {
  background: var(--soft);
  border-radius: 8px;
  color: var(--brand-dark);
  display: grid;
  font-weight: 850;
  min-height: 72px;
  place-items: center;
  text-align: center;
}

.date-pill span {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
}

.card-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.card-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.88rem;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.76rem;
  font-weight: 850;
  line-height: 1;
  padding: 6px 8px;
}

.badge.taller {
  background: #edf1f7;
  color: #334155;
}

.badge.domicilio {
  background: #f7eee9;
  color: var(--accent);
}

.status {
  background: #edf1f7;
  color: #334155;
}

.status.en-proceso {
  background: #fff5db;
  color: var(--warn);
}

.status.pendiente-firma {
  background: #f7e8e3;
  color: #9b3e22;
}

.status.completada {
  background: #e7f4ec;
  color: var(--done);
}

.order-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.order-card p {
  color: var(--muted);
  margin: 0;
}

dialog {
  border: 0;
  padding: 0;
  width: min(1040px, calc(100vw - 24px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.dialog-card {
  padding: 18px;
}

.dialog-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.92fr);
}

.signature-head {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

canvas {
  background: #fbfcfe;
  border: 1px dashed #98a4b7;
  border-radius: 8px;
  height: auto;
  max-width: 100%;
  touch-action: none;
  width: 100%;
}

.photo-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.photo-grid figure {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  overflow: hidden;
  position: relative;
}

.photo-grid img {
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
  width: 100%;
}

.photo-grid button {
  background: rgba(23, 33, 47, 0.82);
  border: 0;
  border-radius: 999px;
  color: white;
  height: 26px;
  position: absolute;
  right: 6px;
  top: 6px;
  width: 26px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.report-card {
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.report-content {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 16px;
  padding-top: 16px;
}

.report-block {
  display: grid;
  gap: 8px;
}

.report-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 150px minmax(0, 1fr);
}

.report-row strong {
  color: var(--muted);
}

.report-photos {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.report-photos img,
.report-signature img {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 100%;
}

.empty-state {
  align-items: center;
  border: 1px dashed #b9c2d0;
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  justify-items: center;
  min-height: 108px;
  padding: 20px;
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

@media (max-width: 940px) {
  .metrics,
  .workspace,
  .dialog-grid,
  .users-layout,
  .clients-layout {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar,
  .panel-header,
  .signature-head,
  .schedule-card {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .dialog-actions {
    justify-content: flex-start;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .search {
    max-width: none;
  }

  .user-card {
    grid-template-columns: 1fr;
  }

  .equipment-form {
    grid-template-columns: 1fr;
  }

  .user-actions {
    justify-content: flex-start;
  }
}

@media print {
  body {
    background: white;
  }

  body > :not(dialog),
  #visitDialog {
    display: none;
  }

  #reportDialog {
    display: block;
    position: static;
    width: auto;
  }

  .report-card {
    border: 0;
    box-shadow: none;
    max-height: none;
  }

  .topbar-actions,
  .icon-button {
    display: none;
  }
}
