:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-soft: #f7f8fa;
  --ink: #17202a;
  --muted: #697481;
  --line: #dfe5ec;
  --green: #147d64;
  --green-soft: #e6f3ef;
  --red: #b43a35;
  --red-soft: #fdeceb;
  --yellow: #956602;
  --yellow-soft: #fff3d4;
  --blue: #2c5d9f;
  --blue-soft: #e8efff;
  --shadow: 0 14px 32px rgba(23, 32, 42, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
  background:
    linear-gradient(135deg, rgba(16, 24, 32, 0.94), rgba(23, 32, 42, 0.86)),
    var(--bg);
}

.login-card {
  display: grid;
  width: min(100%, 420px);
  gap: 22px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  padding: 0;
}

.login-brand h1 {
  margin: 0;
  font-size: 1rem;
}

.login-card h2 {
  margin: 0;
  font-size: 1.8rem;
}

.login-copy {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 800;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 12px;
  background: #101820;
  color: #f8fafc;
}

.brand,
.sidebar-note {
  display: none;
}

.nav-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-list::-webkit-scrollbar {
  display: none;
}

.nav-item {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: transparent;
  color: #dbe3eb;
  font-weight: 800;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav-item strong {
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  text-align: center;
}

.main-content {
  padding: 16px;
}

.topbar {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.logout-btn {
  width: 100%;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  margin: 0;
  font-size: 1.8rem;
}

.mode-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
}

.mode-toggle input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat span,
.stat small {
  display: block;
  color: var(--muted);
}

.stat span {
  font-size: 0.92rem;
}

.stat strong {
  display: block;
  margin: 6px 0 2px;
  font-size: 1.55rem;
}

.toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.search-wrap {
  display: grid;
  gap: 6px;
}

.search-wrap label,
.field label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.search-wrap input,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.search-wrap input,
.field input,
.field select {
  min-height: 44px;
  padding: 0 12px;
}

.field textarea {
  min-height: 88px;
  padding: 10px 12px;
  resize: vertical;
}

.search-wrap input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

.filter-toggle,
.load-more,
.primary-btn,
.text-btn,
.whatsapp-btn,
.whatsapp-link,
.close-detail {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 900;
}

.filter-toggle,
.load-more {
  width: 100%;
  background: #101820;
  color: #ffffff;
}

.filter-panel {
  display: none;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.filter-panel.open {
  display: grid;
}

.field {
  display: grid;
  gap: 6px;
}

.text-btn {
  padding: 0 12px;
  background: var(--panel-soft);
  color: var(--ink);
}

.list-meta {
  display: flex;
  justify-content: space-between;
  margin: 4px 0 10px;
}

.list-meta p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.ticket-grid {
  display: grid;
  gap: 10px;
}

.ticket-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease,
    transform 150ms ease;
}

.ticket-card:hover,
.ticket-card.selected {
  border-color: #9aa7b4;
  box-shadow: var(--shadow);
}

@media (hover: hover) {
  .ticket-card:hover {
    transform: translateY(-2px);
  }
}

.ticket-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.ticket-main h3 {
  margin: 0 0 3px;
  font-size: 1.08rem;
}

.ticket-main p,
.ticket-summary span,
.detail-subtitle,
.question-row span {
  color: var(--muted);
}

.ticket-main p,
.ticket-summary {
  margin: 0;
  font-size: 0.92rem;
}

.ticket-id {
  display: inline-flex;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.ticket-summary {
  display: grid;
  gap: 2px;
}

.status-pill,
.answer-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-pending {
  color: var(--red);
  background: var(--red-soft);
}

.status-scheduled,
.answer-yes {
  color: var(--green);
  background: var(--green-soft);
}

.status-waiting {
  color: var(--yellow);
  background: var(--yellow-soft);
}

.status-closed,
.answer-no {
  color: var(--muted);
  background: var(--panel-soft);
}

.ticket-facts,
.detail-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.ticket-facts div,
.detail-facts div {
  min-width: 0;
  padding: 9px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.ticket-facts dt,
.detail-facts dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.ticket-facts dd,
.detail-facts dd {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--ink);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-photo {
  position: relative;
  height: 132px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel-soft);
}

.card-photo img,
.detail-gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-photo span {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(16, 24, 32, 0.78);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 900;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.primary-btn {
  flex: 1;
  background: #101820;
  color: #ffffff;
}

.whatsapp-btn,
.whatsapp-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #ffffff;
  text-decoration: none;
}

.whatsapp-btn {
  width: 48px;
}

.load-more-wrap {
  margin-top: 12px;
}

.detail-panel {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 8;
  overflow: auto;
  background: var(--bg);
}

.detail-panel.open {
  display: block;
}

.ticket-detail {
  display: grid;
  min-height: 100vh;
  gap: 12px;
  padding: 12px;
}

.detail-header {
  position: sticky;
  top: 0;
  z-index: 9;
  display: grid;
  gap: 10px;
  margin: -12px -12px 0;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.detail-topline,
.detail-actions,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.close-detail {
  display: grid;
  width: 42px;
  place-items: center;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 1.4rem;
}

.detail-header h2 {
  margin: 0;
  font-size: 1.42rem;
}

.detail-subtitle {
  margin: 2px 0 0;
}

.detail-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.detail-section h3 {
  margin: 0;
  font-size: 0.98rem;
}

.client-note p {
  margin: 0;
  line-height: 1.45;
}

.question-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.detail-gallery {
  display: grid;
  gap: 8px;
}

.detail-gallery img {
  height: 220px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.quote-form {
  display: grid;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 20;
  padding: 12px 14px;
  border-radius: 8px;
  background: #101820;
  color: #ffffff;
  box-shadow: var(--shadow);
}

.empty-state {
  padding: 28px 16px;
  border: 1px dashed #b8c2cc;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

@media (min-width: 760px) {
  .app-shell {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
  }

  .app-shell.detail-open {
    grid-template-columns: 236px minmax(480px, 1fr) 420px;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 28px;
    min-height: 100vh;
    padding: 24px 16px;
  }

  .brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 0 8px;
  }

  .brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: #f3c969;
    color: #101820;
    font-weight: 900;
  }

  .brand h1 {
    margin: 0;
    color: #ffffff;
    font-size: 1rem;
  }

  .brand .eyebrow {
    color: #93a0ad;
  }

  .sidebar-note {
    display: block;
    margin-top: auto;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
  }

  .sidebar-note p {
    margin: 0 0 8px;
    color: #aeb9c5;
    font-size: 0.82rem;
  }

  .sidebar-note strong {
    line-height: 1.35;
  }

  .nav-list {
    display: grid;
    overflow: visible;
  }

  .nav-item {
    justify-content: space-between;
    width: 100%;
  }

  .main-content {
    padding: 24px;
  }

  .topbar,
  .toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .mode-toggle {
    min-width: 190px;
  }

  .logout-btn {
    width: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .search-wrap {
    min-width: min(360px, 100%);
  }

  .filter-toggle {
    width: auto;
    padding: 0 18px;
  }

  .filter-panel.open {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .ticket-grid {
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  }

  .detail-panel {
    position: sticky;
    top: 0;
    height: 100vh;
    border-left: 1px solid var(--line);
    background: var(--panel);
  }

  .ticket-detail {
    min-height: auto;
    padding: 18px;
  }

  .detail-header {
    margin: -18px -18px 0;
    padding: 18px;
  }

  .toast {
    right: 24px;
    left: auto;
    max-width: 360px;
  }
}

@media (min-width: 1180px) {
  .app-shell {
    grid-template-columns: 268px minmax(0, 1fr);
  }

  .app-shell.detail-open {
    grid-template-columns: 268px minmax(520px, 1fr) 430px;
  }
}
