*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:   #707b49;
  --green-dk:#5a6239;
  --green-lt:#8a9660;
  --text:    #f0f0f0;
  --sub:     #888888;
  --border:  #2e2e2e;
  --bg:      #111111;
  --card:    #1c1c1c;
  --white:   #ffffff;
  --radius:  14px;
  --nav-h:   64px;
  --hdr-h:   54px;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ── Login ── */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0d0d;
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  padding: 0 24px;
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
  color: #fff;
}

.login-logo img {
  border-radius: 20px;
  margin-bottom: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

.login-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--green);
}

.login-logo p {
  font-size: .9rem;
  opacity: .6;
  margin-top: 4px;
  color: #fff;
}

.login-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

.login-error {
  background: rgba(192,57,43,.15);
  color: #e87c6e;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .875rem;
  margin-bottom: 16px;
  border: 1px solid rgba(192,57,43,.3);
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 16px;
  transition: border-color .2s;
  background: #141414;
  color: var(--text);
}

.field input:focus {
  outline: none;
  border-color: var(--green);
  background: #1a1a1a;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--green);
  color: #000;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

.btn-primary:active { transform: scale(.98); background: var(--green-dk); }

.login-footer {
  text-align: center;
  color: rgba(255,255,255,.4);
  font-size: .8rem;
  margin-top: 20px;
}

/* ── App header ── */
.app-view {
  min-height: 100dvh;
  padding-bottom: var(--nav-h);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--hdr-h);
  background: var(--green);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.app-header-title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #000;
}

.app-header-user {
  font-size: .85rem;
  background: rgba(0,0,0,.15);
  color: #000;
  padding: 4px 10px;
  border-radius: 20px;
}

/* ── Main ── */
.app-main {
  padding: 16px 16px 8px;
  max-width: 500px;
  margin: 0 auto;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

.section-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sub);
  margin-bottom: 14px;
}

/* ── Nivel card ── */
.nivel-card {
  background: var(--card) !important;
  border: 1.5px solid var(--nivel-color, var(--green)) !important;
}

.nivel-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.nivel-icon { font-size: 2.2rem; }

.nivel-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--nivel-color, var(--green));
}

.nivel-sub {
  font-size: .8rem;
  color: var(--sub);
  margin-top: 2px;
}

.progreso-bar {
  height: 8px;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progreso-fill {
  height: 100%;
  background: var(--nivel-color, var(--green));
  border-radius: 4px;
  transition: width .6s ease;
}

.nivel-meta {
  font-size: .8rem;
  color: var(--sub);
}

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-val {
  font-size: 1rem;
  font-weight: 800;
  color: var(--green);
  line-height: 1.2;
}

.stat-lbl {
  font-size: .7rem;
  color: var(--sub);
  margin-top: 4px;
}

/* ── Frase ── */
.frase-display {
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text);
  background: rgba(112,123,73,.1);
  padding: 10px 14px;
  border-radius: 8px;
  border-left: 3px solid var(--green);
}

.frase-empty {
  font-size: .875rem;
  color: var(--sub);
}

.frase-desc {
  font-size: .85rem;
  color: var(--sub);
  margin-bottom: 14px;
  line-height: 1.5;
}

/* ── Orders ── */
.order-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.order-row:last-of-type { border-bottom: none; }

.order-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.order-id {
  font-weight: 700;
  font-size: .9rem;
}

.order-date {
  font-size: .75rem;
  color: var(--sub);
}

.link-ver-todos {
  display: block;
  text-align: center;
  margin-top: 12px;
  color: var(--green);
  font-size: .875rem;
  font-weight: 600;
  text-decoration: none;
}

/* ── Order cards (pedidos tab) ── */
.order-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.order-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.order-card-body {
  display: flex;
  justify-content: space-between;
  font-size: .875rem;
  color: var(--sub);
  margin-bottom: 8px;
}

.order-total { font-weight: 700; color: var(--text); }

.order-items {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.order-item {
  font-size: .75rem;
  background: rgba(255,255,255,.06);
  padding: 3px 8px;
  border-radius: 20px;
  color: var(--sub);
}

.order-item-more {
  font-size: .75rem;
  color: var(--sub);
  padding: 3px 0;
}

/* ── Badges ── */
.badge {
  font-size: .7rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge-blue   { background: rgba(29,78,216,.2);  color: #93b4f5; }
.badge-yellow { background: rgba(180,83,9,.2);   color: #fbbf5a; }
.badge-green  { background: rgba(112,123,73,.25); color: #a8b878; }
.badge-red    { background: rgba(153,27,27,.2);  color: #f08080; }
.badge-gray   { background: rgba(255,255,255,.08); color: #aaa; }
.badge-purple { background: rgba(91,33,182,.2);  color: #c4a8f5; }

/* ── Pagination ── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.btn-pag {
  display: inline-block;
  padding: 8px 18px;
  border: 1.5px solid var(--green);
  border-radius: 8px;
  color: var(--green);
  font-size: .875rem;
  font-weight: 600;
  text-decoration: none;
}

/* ── Profile ── */
.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}

.profile-row:last-child { border-bottom: none; }
.profile-row span { color: var(--sub); }

/* ── Alerts ── */
.alert-success {
  background: rgba(112,123,73,.2);
  color: #a8b878;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .875rem;
  margin-bottom: 14px;
  border: 1px solid rgba(112,123,73,.4);
}

.alert-error {
  background: rgba(153,27,27,.2);
  color: #f08080;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .875rem;
  margin-bottom: 14px;
  border: 1px solid rgba(153,27,27,.4);
}

/* ── Logout ── */
.btn-logout {
  display: block;
  text-align: center;
  padding: 12px;
  color: #e87c6e;
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  border: 1.5px solid rgba(192,57,43,.4);
  border-radius: 10px;
}

.empty-msg {
  color: var(--sub);
  font-size: .9rem;
  text-align: center;
  padding: 16px 0;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: #0d0d0d;
  border-top: 1px solid var(--border);
  display: flex;
  box-shadow: 0 -2px 10px rgba(0,0,0,.3);
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #555;
  text-decoration: none;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  transition: color .15s;
}

.nav-item svg {
  width: 22px;
  height: 22px;
}

.nav-item.active {
  color: var(--green);
}

/* ── Safe area ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
  .app-view { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}

/* ── IAN native chat ── */
.app-view.tab-ian .app-main {
  padding: 0;
  max-width: 100%;
}

.ian-chat {
  position: fixed;
  top: var(--hdr-h);
  left: 0;
  right: 0;
  bottom: var(--nav-h);
  display: flex;
  flex-direction: column;
  background: #0d0d0d;
}

@supports (bottom: env(safe-area-inset-bottom)) {
  .ian-chat {
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
}

.ian-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.ian-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: #555;
}

.ian-empty-icon { font-size: 2.5rem; margin-bottom: 10px; }
.ian-empty-title { font-size: 1.1rem; font-weight: 700; color: #ccc; margin-bottom: 6px; }
.ian-empty-sub { font-size: .875rem; line-height: 1.5; }

.ian-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 2px;
}

.ian-user { align-self: flex-end; align-items: flex-end; }
.ian-bot  { align-self: flex-start; align-items: flex-start; }

.ian-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .9rem;
  line-height: 1.45;
  word-break: break-word;
}

.ian-user .ian-bubble {
  background: var(--green);
  color: #000;
  border-bottom-right-radius: 4px;
}

.ian-bot .ian-bubble {
  background: #2a2a2a;
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.ian-ts {
  font-size: .65rem;
  color: #444;
  padding: 0 4px;
}

/* typing indicator */
.ian-typing {
  display: none;
  align-self: flex-start;
}

.ian-typing.visible { display: flex; }

.ian-typing-bubble {
  background: #2a2a2a;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 10px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.ian-typing-bubble .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #555;
  animation: dotBounce 1.2s infinite ease-in-out;
}

.ian-typing-bubble .dot:nth-child(2) { animation-delay: .2s; }
.ian-typing-bubble .dot:nth-child(3) { animation-delay: .4s; }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* input area */
.ian-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: #161616;
  border-top: 1px solid var(--border);
}

.ian-input {
  flex: 1;
  border: 1.5px solid #333;
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  background: #222;
  color: var(--text);
  transition: border-color .15s;
  font-family: inherit;
}

.ian-input::placeholder { color: #555; }
.ian-input:focus { border-color: var(--green); background: #272727; }

.ian-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s;
}

.ian-send:disabled { opacity: .35; }
.ian-send svg { width: 20px; height: 20px; }

/* iOS: prevent auto-zoom on input focus */
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  font-size: 16px !important;
}
