:root {
  --bg: #eef4fb;
  --panel: #ffffff;
  --panel-border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --ink: #0f172a;
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

html {
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at 8% 14%, rgba(37, 99, 235, 0.22) 0%, transparent 34%),
    radial-gradient(circle at 88% 20%, rgba(15, 118, 110, 0.18) 0%, transparent 32%),
    radial-gradient(circle at 78% 78%, rgba(15, 23, 42, 0.10) 0%, transparent 30%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  width: 100%;
  position: relative;
  overflow-x: clip;
}

main,
.container,
.panel {
  max-width: 100%;
}

a {
  color: var(--primary);
}

.container {
  width: min(1180px, 100% - 32px);
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.97);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(4px);
}

.topbar-inner {
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.2px;
  font-size: 22px;
}

.menu {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.menu a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.menu a:hover {
  color: #fff;
  background: rgba(148, 163, 184, 0.2);
}

.menu-toggle {
  display: none;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.45);
  border-radius: 10px;
  padding: 9px 8px;
  width: 42px;
  height: 38px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-direction: column;
}

.menu-toggle span {
  width: 20px;
  height: 2px;
  border-radius: 99px;
  background: #e2e8f0;
}

body.nav-mobile .menu-toggle {
  display: inline-flex !important;
}

body.nav-mobile .menu {
  position: fixed;
  top: 58px;
  left: 10px;
  right: 10px;
  display: none !important;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35);
}

body.nav-mobile .menu.is-open {
  display: flex !important;
}

body.nav-mobile .menu a {
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 10px;
  width: 100%;
}

body.nav-mobile .recent-work-orders table th:nth-child(3),
body.nav-mobile .recent-work-orders table td:nth-child(3),
body.nav-mobile .recent-work-orders table th:nth-child(4),
body.nav-mobile .recent-work-orders table td:nth-child(4) {
  display: none !important;
}

body.nav-mobile .clients-list table th:nth-child(2),
body.nav-mobile .clients-list table td:nth-child(2) {
  display: none !important;
}

/* Fallback iPhone/iOS: aplica móvil aunque falle JS */
@media (max-width: 1024px) {
  .menu-toggle {
    display: inline-flex !important;
  }

  .menu {
    position: fixed;
    top: 58px;
    left: 10px;
    right: 10px;
    display: none !important;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35);
  }

  .menu.is-open {
    display: flex !important;
  }

  .recent-work-orders table th:nth-child(3),
  .recent-work-orders table td:nth-child(3),
  .recent-work-orders table th:nth-child(4),
  .recent-work-orders table td:nth-child(4) {
    display: none !important;
  }

  .clients-list table th:nth-child(2),
  .clients-list table td:nth-child(2) {
    display: none !important;
  }

  .work-orders-list .table-wrap {
    overflow: visible;
  }

  .work-orders-list table,
  .work-orders-list thead,
  .work-orders-list tbody,
  .work-orders-list tr,
  .work-orders-list th,
  .work-orders-list td {
    display: block;
    width: 100%;
  }

  .work-orders-list thead {
    display: none;
  }

  .work-orders-list table {
    border: 0;
    background: transparent;
  }

  .work-orders-list tbody tr {
    background: #fff;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 10px;
    box-shadow: var(--shadow);
  }

  .work-orders-list tbody td {
    border: 0;
    padding: 6px 0 6px 110px;
    position: relative;
    min-height: 28px;
    font-size: 13px;
  }

  .work-orders-list tbody td::before {
    position: absolute;
    left: 0;
    top: 6px;
    width: 100px;
    color: #64748b;
    font-weight: 700;
    font-size: 12px;
  }

  .work-orders-list tbody td:nth-child(1)::before { content: "Cliente"; }
  .work-orders-list tbody td:nth-child(2)::before { content: "Título"; }
  .work-orders-list tbody td:nth-child(3)::before { content: "Categoría"; }
  .work-orders-list tbody td:nth-child(4)::before { content: "Estado"; }
  .work-orders-list tbody td:nth-child(5)::before { content: "Inicio"; }
  .work-orders-list tbody td:nth-child(6)::before { content: ""; }

  .work-orders-list tbody td:last-child {
    padding-left: 0;
    margin-top: 4px;
  }

  .work-orders-list tbody td:last-child .btn.view {
    width: 100%;
    min-height: 40px;
  }
}

main.container {
  padding: 24px 0 40px;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.90) 100%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.panel h1,
.panel h2 {
  margin-top: 0;
  margin-bottom: 14px;
  letter-spacing: 0.2px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  background: linear-gradient(160deg, #ffffff 0%, #f8fafc 62%, #edf4ff 100%);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.metric {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  text-decoration: none;
  transition: transform 0.05s ease, background 0.2s ease;
}

.btn:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}

.btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  background: linear-gradient(135deg, #475569 0%, #334155 100%);
}

.btn.view {
  background: linear-gradient(135deg, #06b6d4 0%, #2563eb 100%);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
  min-width: 70px;
  padding: 8px 12px;
  border-radius: 999px;
}

.btn.view::before {
  content: "👁";
  font-size: 12px;
  line-height: 1;
}

.btn.view:hover {
  background: linear-gradient(135deg, #0891b2 0%, #1d4ed8 100%);
}

.btn.success {
  background: linear-gradient(135deg, #0f766e 0%, #0b5f59 100%);
}

.btn.warning {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}

.btn.danger {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

form {
  display: grid;
  gap: 10px;
}

label {
  font-size: 13px;
  color: #334155;
  font-weight: 600;
  margin-bottom: 3px;
  display: block;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="datetime-local"] {
  min-width: 0;
  max-width: 100%;
}

input[type="file"] {
  border: 1px dashed #94a3b8;
  background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
  padding: 8px;
}

input[type="file"]::file-selector-button {
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #4f46e5 0%, #2563eb 100%);
  color: #fff;
  font-weight: 600;
  padding: 8px 12px;
  margin-right: 10px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

input[type="file"]::file-selector-button:hover {
  opacity: 0.92;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #60a5fa;
  outline: 2px solid #bfdbfe;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.filters-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 180px;
  gap: 12px;
  align-items: end;
}

.filter-btn {
  width: 100%;
}

.section-toolbar {
  margin-bottom: 14px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.checkline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.checkline label {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

thead tr {
  background: #f8fafc;
}

th,
td {
  text-align: left;
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid #e2e8f0;
  word-break: break-word;
}

th {
  color: #334155;
  font-weight: 700;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.status {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 110px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-transform: capitalize;
}

.status.abierto {
  background: #0f766e;
}

.status.pausado {
  background: #2563eb;
}

.status.finalizado_dia {
  background: #1d4ed8;
}

.status.finalizado {
  background: #0f172a;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 2px;
}

.timeline li {
  position: relative;
  margin-bottom: 12px;
  padding: 12px 12px 12px 14px;
  border: 1px solid #dbeafe;
  background: #f8fbff;
  border-radius: 12px;
}

.timeline li::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  position: absolute;
  left: -5px;
  top: 16px;
  box-shadow: 0 0 0 3px #dbeafe;
}

.event-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 900;
}

.event-modal {
  position: fixed;
  z-index: 901;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(680px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  margin: 0;
  background: #ffffff;
  opacity: 1;
}

.event-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

body.modal-open {
  overflow: hidden;
}

.alert {
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
  font-size: 14px;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}

.image-preview {
  max-width: 280px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  margin-top: 6px;
}

ul {
  padding-left: 18px;
}

@media (max-width: 900px) {
  body.menu-open {
    overflow: hidden;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .filters-row {
    grid-template-columns: 1fr;
  }

  .metric {
    font-size: 26px;
  }

}

@media (max-width: 600px) {
  .container {
    width: min(1180px, 100% - 18px);
    padding-left: 0;
    padding-right: 0;
  }

  .topbar-inner {
    min-height: 58px;
    padding: 6px 0;
  }

  .brand {
    font-size: 19px;
  }

  .panel {
    padding: 14px;
    border-radius: 12px;
  }

  .actions {
    gap: 6px;
  }

  .actions .btn,
  form .btn {
    width: 100%;
  }

  .btn {
    min-height: 42px;
  }

  .btn.view {
    min-width: 64px;
    width: auto;
    min-height: 36px;
    padding: 7px 10px;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  input[type="datetime-local"] {
    display: block;
    width: calc(100% - 14px);
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
    padding: 10px;
    margin-right: 14px;
  }

  .event-modal {
    width: calc(100% - 12px);
    left: 6px;
    right: 6px;
    top: 12px;
    transform: none;
    max-height: calc(100vh - 24px);
    border-radius: 12px;
  }

  .cards-billing {
    gap: 10px;
  }

  .cards-billing .card {
    padding: 14px;
  }

  .cards-billing .card h3 {
    font-size: 14px;
    margin-bottom: 5px;
  }

  .cards-billing .metric {
    font-size: 36px;
    line-height: 1.05;
  }

  table {
    min-width: 0;
    white-space: normal;
    table-layout: fixed;
  }

  th,
  td {
    padding: 8px;
    font-size: 12px;
  }

  .status {
    min-width: 0;
    padding: 6px 8px;
    font-size: 11px;
  }
}
