:root {
  --primary: #6b4eff;
  --secondary: #ec4899;
  --accent: #f9a8d4;
  --background: #ffeaf4;
  --surface: #fff6fb;
  --border: #f2c7e3;
  --text: #573c86;
  --muted: #786b82;
  --danger: #e11d48;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: linear-gradient(135deg, var(--background), var(--surface));
  min-height: 100vh;
}

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

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  color: white;
  background: var(--secondary);
  font-weight: 800;
  cursor: pointer;
}

button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
}

label { display: grid; gap: 6px; font-weight: 700; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.offline-banner {
  position: fixed;
  z-index: 100;
  inset: 0 0 auto;
  padding: 9px;
  text-align: center;
  color: white;
  background: var(--danger);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 30px;
  border: 2px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(66, 31, 95, .15);
}

.login-card h1, .login-card p { margin: 0; }
.login-brand { font-size: 38px; }
.eyebrow { color: var(--muted); font-weight: 800; }

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px 16px;
  border-right: 2px solid var(--border);
  background: var(--surface);
}

.brand { font-size: 20px; font-weight: 900; }
.brand-subtitle { color: var(--muted); font-size: 13px; font-weight: 800; }

.nav { display: grid; gap: 8px; margin-top: 24px; }

.nav-item {
  border-radius: 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
}

.nav-item.active { color: white; background: var(--secondary); }
.nav-item.disabled { opacity: .4; }

.sidebar-user {
  display: grid;
  gap: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.main { padding: 24px; }

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

.header h1 { margin: 3px 0 0; }

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

.header-actions input { min-width: 280px; }

.secondary-button {
  color: var(--text);
  background: transparent;
  border: 2px solid var(--border);
}

.danger-button { background: var(--danger); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.summary-card, .panel, .appointment-card {
  border: 2px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 4px 18px rgba(66, 31, 95, .07);
}

.summary-card { display: grid; gap: 8px; padding: 18px; }
.summary-card strong { font-size: 30px; }

.panel { margin-top: 18px; padding: 18px; }

.panel-head, .appointment-top, .dialog-head, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2, .panel-head p { margin: 0 0 4px; }

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

.filter-button {
  color: var(--text);
  background: transparent;
  border: 2px solid var(--border);
}

.filter-button.active { color: white; background: var(--secondary); }

#appointments-list, #dashboard-appointments {
  display: grid;
  gap: 12px;
}

.appointment-card { padding: 16px; }

.appointment-meta, .appointment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
}

.status {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
  background: var(--border);
}

.status-confirmed { background: #dbeafe; color: #1d4ed8; }
.status-arrived { background: #dcfce7; color: #15803d; }
.status-in_progress { background: #fef3c7; color: #a16207; }
.status-completed { background: #e0e7ff; color: #4338ca; }
.status-canceled, .status-no_show { background: #ffe4e6; color: #be123c; }

.message { min-height: 22px; margin: 8px 0; }
.message.error { color: var(--danger); }
.message.success { color: #15803d; }

.empty-state {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

dialog {
  width: min(760px, 94vw);
  border: 0;
  border-radius: 20px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop { background: rgba(20, 10, 30, .45); }

.dialog-form { padding: 20px; }
.dialog-head h2 { margin: 0; }

.icon-button {
  padding: 6px 11px;
  color: var(--text);
  background: transparent;
  font-size: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 18px 0;
}

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

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 2px solid var(--border); }
  .nav { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .header { align-items: stretch; flex-direction: column; }
  .header-actions { align-items: stretch; flex-direction: column; }
  .header-actions input { min-width: 0; }
}

@media (max-width: 560px) {
  .main { padding: 14px; }
  .summary-grid, .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
}
/* Mejoras para celulares */
@media (max-width: 700px) {
  .layout {
    display: block;
  }

  .sidebar {
    position: static;
    padding: 14px;
    gap: 14px;
  }

  .brand {
    font-size: 18px;
  }

  .nav {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: thin;
  }

  .nav-item {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
    padding: 9px 14px;
  }

  .nav-item.disabled {
    display: none;
  }

  .sidebar-user {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 10px;
  }

  .sidebar-user .small {
    grid-column: 1;
  }

  .sidebar-user button {
    grid-column: 2;
    grid-row: 1 / 3;
  }

  .main {
    padding: 12px;
  }

  .header {
    gap: 12px;
    margin-bottom: 12px;
  }

  .header h1 {
    font-size: 24px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .header-actions input {
    min-width: 0;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .summary-card {
    padding: 14px;
  }

  .summary-card span {
    font-size: 13px;
  }

  .summary-card strong {
    font-size: 26px;
  }

  .panel {
    margin-top: 12px;
    padding: 13px;
  }

  .panel-head {
    align-items: flex-start;
  }

  .panel-head h2 {
    font-size: 20px;
  }

  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 14px -2px;
    padding: 2px 2px 8px;
  }

  .filter-button {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }

  .appointment-card {
    padding: 14px;
  }

  .appointment-top {
    align-items: flex-start;
  }

  .appointment-meta {
    display: grid;
    gap: 5px;
    font-size: 14px;
  }

  .appointment-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .appointment-actions button {
    width: 100%;
    min-height: 44px;
    padding: 9px;
  }

  dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }

  .dialog-form {
    padding: 15px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .dialog-actions {
    position: sticky;
    bottom: 0;
    padding-top: 12px;
    background: var(--surface);
  }

  .dialog-actions button {
    flex: 1;
    min-height: 46px;
  }
}

@media (max-width: 390px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }

  .appointment-actions {
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
  }

  .panel-head > button {
    width: 100%;
  }
}
