:root {
  /* Color */
  --bg: #0f1417;
  --surface: #1a2229;
  --surface-raised: #212b33;
  --border: #2a343d;
  --text: #e8ecef;
  --text-dim: #7c8894;
  --accent: #4fa8e8;
  --accent-dim: #2d4a5e;
  --success: #4caf7d;
  --warning: #e0a030;
  --danger: #e0555a;

  /* Type */
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;

  /* Layout */
  --radius: 6px;
  --radius-lg: 10px;
  --nav-height: 60px;
  --topbar-height: 52px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

/* Focus visibility, kept even in dark mode */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Top bar ---------- */

.topbar {
  height: var(--topbar-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__back {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  line-height: 1;
}

.topbar__title {
  font-weight: 600;
  font-size: 16px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__mono {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 13px;
}

.topbar__logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.topbar__logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- Main content area ---------- */

.view {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-height) + 16px);
}

.container {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Bottom nav ---------- */

.bottomnav {
  height: var(--nav-height);
  flex: 0 0 auto;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottomnav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  padding: 6px 0 4px;
}

.bottomnav__item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.bottomnav__item.is-active {
  color: var(--accent);
}

/* ---------- Login ---------- */

.login {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
}

.login__brand {
  text-align: center;
  margin-bottom: 40px;
}

.login__mark {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: 6px;
}

.login__title {
  font-size: 22px;
  font-weight: 600;
}

.login__subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field textarea {
  resize: vertical;
  min-height: 90px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #08131a;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn {
  width: auto;
  flex: 1;
}

.error-msg {
  background: rgba(224, 85, 90, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- Filter bar ---------- */

.filterbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-height);
  z-index: 10;
}

.filterbar input[type="search"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
}

.filterbar select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--text);
}

/* ---------- Ticket / client list rows ---------- */

.list {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  cursor: pointer;
  background: var(--bg);
  text-align: left;
  width: 100%;
  color: inherit;
}

.row:hover {
  background: var(--surface);
}

.row--open {
  border-left-color: var(--accent);
}

.row--closed {
  border-left-color: var(--success);
}

.row--overdue {
  border-left-color: var(--danger);
}

.row__body {
  flex: 1;
  min-width: 0;
}

.row__code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.row__title {
  font-weight: 600;
  font-size: 14.5px;
  margin: 3px 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row__meta {
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row__badge {
  align-self: center;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 99px;
  font-weight: 600;
  white-space: nowrap;
  height: fit-content;
}

.badge--open {
  background: var(--accent-dim);
  color: var(--accent);
}

.badge--closed {
  background: rgba(76, 175, 125, 0.14);
  color: var(--success);
}

/* ---------- Empty / loading / error states ---------- */

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

.state__icon {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

.state__title {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}

/* ---------- Detail view ---------- */

.detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-header__code {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 13px;
  margin-bottom: 6px;
}

.detail-header__title {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 10px;
}

.chip-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 99px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.section__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 13.5px;
}

.kv dt {
  color: var(--text-dim);
}

.kv dd {
  margin: 0;
  text-align: right;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline__item {
  display: flex;
  gap: 10px;
  font-size: 13px;
}

.timeline__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex: 0 0 auto;
}

.timeline__ts {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- FAB (nuevo ticket) ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #08131a;
  border: none;
  font-size: 26px;
  box-shadow: 0 6px 18px rgba(79, 168, 232, 0.35);
  cursor: pointer;
  z-index: 15;
}

/* ---------- Autocomplete (búsqueda de cliente en alta de ticket) ---------- */

.autocomplete {
  position: relative;
}

.autocomplete__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
}

.autocomplete__result {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}

.autocomplete__result:last-child {
  border-bottom: none;
}

.autocomplete__result:hover {
  background: var(--surface);
}

.autocomplete__selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13.5px;
}

.autocomplete__clear {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  z-index: 50;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.toast--success {
  border-color: var(--success);
}

.toast--error {
  border-color: var(--danger);
}

/* Small helper */
.mono {
  font-family: var(--font-mono);
}

.text-dim {
  color: var(--text-dim);
}

.mt-16 {
  margin-top: 16px;
}
