/* Desenvolvimento: Jhonatan Cieslak, jhonatan.cieslak94@gmail.com, +351 935 834 214 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --blue: #2563EB;
  --blue-dark: #1D4ED8;
  --navy: #0F172A;
  --navy-mid: #1E293B;
  --text: #1E293B;
  --muted: #64748B;
  --light: #F8FAFC;
  --border: #E2E8F0;
  --white: #FFFFFF;
  --green: #16A34A;
  --green-soft: #DCFCE7;
  --red: #DC2626;
  --red-soft: #FEE2E2;
  --amber: #D97706;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: var(--light);
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout autenticado ── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--navy);
  color: #E2E8F0;
  padding: 1.25rem 0;
  transition: width .18s ease;
  overflow-x: hidden;
}
.sidebar-brand { display: flex; align-items: center; gap: .5rem; padding: 0 1.25rem 1.5rem; }
.sidebar-brand img.sidebar-logo-full { height: 42px; transition: opacity .15s ease; }
.sidebar-logo-mark {
  display: none; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px; background: rgba(255,255,255,.06); flex-shrink: 0;
}
.sidebar-logo-mark img { height: 30px; width: 30px; }
.sidebar-toggle {
  margin-left: auto; background: transparent; border: none; color: #94A3B8; cursor: pointer;
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; flex-shrink: 0;
}
.sidebar-toggle svg { width: 16px; height: 16px; transition: transform .18s ease; }
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav a, .sidebar nav summary {
  display: flex; align-items: center; padding: .65rem 1.25rem; color: #CBD5E1; cursor: pointer;
  font-size: .9rem; font-weight: 500; white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.nav-icon { width: 22px; height: 22px; margin-right: .75rem; flex-shrink: 0; opacity: .85; transition: opacity .15s ease; }
.sidebar nav a:hover .nav-icon, .sidebar nav a.active .nav-icon, .sidebar details[open] summary .nav-icon { opacity: 1; }
.sidebar nav a:hover, .sidebar nav summary:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--blue); color: #fff; }
.sidebar details summary { list-style: none; }
.sidebar details summary::-webkit-details-marker { display: none; }
.sidebar details[open] summary { color: #fff; }
.sidebar details summary::after {
  content: ''; width: 8px; height: 8px; margin-left: auto; flex-shrink: 0;
  border-right: 1.75px solid currentColor; border-bottom: 1.75px solid currentColor;
  transform: rotate(45deg); transition: transform .2s ease; opacity: .6;
}
.sidebar details[open] summary::after { transform: rotate(-135deg); }

/* Submenu: expande/colapsa suavemente via grid-template-rows (sem JS) */
.sidebar details .submenu {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .22s ease;
}
.sidebar details[open] .submenu { grid-template-rows: 1fr; }
.sidebar details .submenu > ul { overflow: hidden; min-height: 0; }
.sidebar details ul a {
  padding-left: 1.25rem; font-size: .85rem; gap: .65rem;
}
.sidebar details ul a .nav-dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55;
  flex-shrink: 0; margin-left: .4rem;
}
.sidebar details ul a:hover .nav-dot, .sidebar details ul a.active .nav-dot { opacity: 1; }

/* ── Sidebar encolhida ── */
.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0 0 1.25rem; }
.sidebar.collapsed .sidebar-logo-full { display: none; }
.sidebar.collapsed .sidebar-logo-mark { display: flex; }
.sidebar.collapsed .sidebar-toggle { display: none; }
.sidebar.collapsed nav a, .sidebar.collapsed nav summary { justify-content: center; padding: .7rem 0; }
.sidebar.collapsed .nav-icon { margin-right: 0; width: 24px; height: 24px; }
.sidebar.collapsed .nav-label, .sidebar.collapsed details summary::after { display: none; }
.sidebar.collapsed details .submenu { grid-template-rows: 0fr !important; }
.sidebar-expand-toggle {
  display: none; position: absolute; top: 1.1rem; right: -13px; width: 26px; height: 26px;
  background: var(--navy); border: 2px solid var(--light); border-radius: 50%;
  color: #94A3B8; align-items: center; justify-content: center; cursor: pointer;
}
.sidebar-expand-toggle svg { width: 14px; height: 14px; }
.sidebar.collapsed { position: relative; }
.sidebar.collapsed .sidebar-expand-toggle { display: flex; }
.sidebar.collapsed .sidebar-expand-toggle svg { transform: rotate(180deg); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.5rem; background: var(--white); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar .user-menu { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: .75rem; }

.content { padding: 1.5rem; flex: 1; }

.footer { padding: 1rem 1.5rem; font-size: .8rem; color: var(--muted); text-align: center; }

/* ── Plano e Faturação ── */
.plan-progress { height: 8px; border-radius: 999px; background: var(--light); overflow: hidden; margin: .6rem 0 .3rem; }
.plan-progress > div { height: 100%; background: var(--blue); border-radius: 999px; transition: width .3s ease; }
.plan-progress.warn > div { background: var(--amber); }
.plan-progress.danger > div { background: var(--red); }
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.5rem; }
@media (max-width: 900px) { .plan-grid { grid-template-columns: 1fr; } }
.plan-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; display: flex; flex-direction: column; }
.plan-card.current { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue), var(--shadow); }
.plan-card h3 { margin: 0 0 .2rem; font-size: 1.05rem; }
.plan-card .plan-price { font-size: 1.5rem; font-weight: 700; color: var(--navy); margin: .3rem 0 .2rem; }
.plan-card .plan-alvo { color: var(--muted); font-size: .82rem; margin: 0 0 1rem; }
.plan-card ul { list-style: none; margin: 0 0 1.25rem; padding: 0; flex: 1; }
.plan-card li { display: flex; align-items: flex-start; gap: .5rem; font-size: .85rem; margin-bottom: .55rem; color: var(--text); }
.plan-card li svg { width: 15px; height: 15px; color: var(--green); flex-shrink: 0; margin-top: .1rem; }

/* ── Header: notificações + avatar ── */
.header-actions { display: flex; align-items: center; gap: .5rem; }
.icon-btn {
  position: relative; width: 34px; height: 34px; border-radius: 8px; border: none;
  background: transparent; color: var(--muted); display: flex; align-items: center;
  justify-content: center; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--light); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-badge {
  position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 999px; background: var(--red); color: #fff; font-size: .62rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.user-menu { position: relative; }
.user-menu-trigger {
  display: flex; align-items: center; gap: .5rem; background: transparent; border: none;
  cursor: pointer; padding: .3rem .5rem .3rem .3rem; border-radius: 999px;
}
.user-menu-trigger:hover { background: var(--light); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700;
  flex-shrink: 0;
}
.user-menu-trigger .user-name { font-size: .85rem; color: var(--text); font-weight: 500; }
.user-menu-trigger .chev { width: 14px; height: 14px; color: var(--muted); transition: transform .15s ease; }
.user-menu.open .user-menu-trigger .chev { transform: rotate(180deg); }
.user-menu-dropdown {
  position: absolute; top: calc(100% + .5rem); right: 0; min-width: 210px;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15,23,42,.12); padding: .4rem; z-index: 20;
  display: none; flex-direction: column;
}
.user-menu.open .user-menu-dropdown { display: flex; }
.user-menu-dropdown a {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 6px;
  color: var(--text); font-size: .87rem; font-weight: 500;
}
.user-menu-dropdown a:hover { background: var(--light); text-decoration: none; }
.user-menu-dropdown a svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.user-menu-dropdown hr { border: none; border-top: 1px solid var(--border); margin: .35rem .2rem; }
.user-menu-dropdown a.danger { color: #991B1B; }
.user-menu-dropdown a.danger svg { color: #991B1B; }

/* ── Flash messages ── */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.flash-danger { background: var(--red-soft); color: #991B1B; }
.flash-success { background: var(--green-soft); color: #166534; }
.flash-info { background: #DBEAFE; color: #1E3A8A; }

/* ── Cards / KPIs ── */
.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-2 { grid-template-columns: 1fr 1fr; } }

.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 1.1rem 1.25rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; }

.kpi-label { font-size: .8rem; color: var(--muted); margin: 0 0 .25rem; }
.kpi-value { font-size: 1.8rem; font-weight: 700; margin: 0; color: var(--navy); }

/* ── Tabela ── */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--light); }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-green { background: var(--green-soft); color: #166534; }
.badge-red { background: var(--red-soft); color: #991B1B; }
.badge-gray { background: #F1F5F9; color: var(--muted); }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-blue { background: #DBEAFE; color: #1E3A8A; }

/* ── Relatórios ── */
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 900px) { .report-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .report-grid { grid-template-columns: 1fr; } }
.report-card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.report-card-head h3 { margin: 0; font-size: 1rem; }
.report-card p { font-size: .85rem; color: var(--muted); margin: 0 0 .8rem; min-height: 2.6em; }
.report-card-disabled { opacity: .65; }

/* ── Botões ── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: var(--radius); border: 1px solid transparent;
  font-size: .88rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-outline { background: var(--white); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--red-soft); color: #991B1B; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

.actions-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: .9rem;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.checkbox-field { display: flex; align-items: center; gap: .5rem; }
.checkbox-field input { width: auto; }

.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: .75rem; }
.breadcrumb a { color: var(--muted); }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* ── Quiosque ── */
.kiosk-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy); padding: 1rem; }
.kiosk-card { background: var(--white); border-radius: 16px; padding: 2.5rem; max-width: 420px; width: 100%; text-align: center; }
.kiosk-card img { height: 44px; margin-bottom: 1.25rem; }
.kiosk-card input {
  width: 100%; font-size: 1.8rem; text-align: center; letter-spacing: .4rem;
  padding: .75rem; border: 2px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem;
}
.kiosk-card .btn { width: 100%; justify-content: center; padding: .8rem; font-size: 1rem; }

/* ── Login / Registo ── */
.auth-wrap { min-height: 100vh; display: flex; background: var(--white); }
.auth-side {
  flex: 1; position: relative; overflow: hidden;
  background: linear-gradient(155deg, var(--navy) 0%, var(--navy-mid) 100%);
  color: #fff; display: none;
  align-items: center; justify-content: center; padding: 3.5rem;
}
.auth-side::before {
  content: ''; position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
                     linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 36px 36px;
}
.auth-side::after {
  content: ''; position: absolute; right: -140px; top: -140px; width: 420px; height: 420px;
  background: radial-gradient(circle, rgba(37,99,235,.35), transparent 70%);
}
.auth-side > div { position: relative; z-index: 1; max-width: 420px; }
.auth-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 2rem; }
.auth-brand img { height: 34px; }
.auth-side h2 { font-size: 1.6rem; font-weight: 700; margin: 0 0 .6rem; letter-spacing: -.01em; }
.auth-side p { color: #B9C2D9; font-size: .98rem; margin: 0; }
.auth-side-illustration { height: auto !important; width: 100%; max-width: 320px; margin: 2rem 0 0 !important; opacity: .95; }
.auth-trust-row { display: flex; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }
.auth-trust-row span { display: flex; align-items: center; gap: .35rem; font-size: .78rem; color: #94A3B8; font-weight: 600; }
.auth-trust-row svg { width: 14px; height: 14px; color: #4ADE80; flex-shrink: 0; }
@media (min-width: 900px) { .auth-side { display: flex; } }

.auth-form-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-form { max-width: 400px; width: 100%; }
.auth-form-logo { display: flex; align-items: center; gap: .5rem; margin-bottom: 2rem; }
.auth-form-logo img { height: 30px; }
@media (min-width: 900px) { .auth-form-logo { display: none; } }
.auth-form h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 .35rem; letter-spacing: -.01em; }
.auth-form .auth-sub { color: var(--muted); font-size: .92rem; margin: 0 0 1.5rem; }
.auth-form .btn-primary { padding: .7rem 1rem; font-size: .92rem; }
.auth-footer-link { margin-top: 1.5rem; font-size: .87rem; color: var(--muted); text-align: center; }

/* ── IA: chat ── */
.chat-shell { display: flex; gap: 1.25rem; height: calc(100vh - 220px); min-height: 480px; }
.chat-sidebar {
  width: 240px; flex-shrink: 0; background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
.chat-sidebar-head { padding: .9rem; border-bottom: 1px solid var(--border); }
.chat-list { flex: 1; overflow-y: auto; padding: .5rem; }
.chat-list-item {
  display: flex; align-items: center; gap: .4rem; padding: .55rem .6rem; border-radius: 8px;
  font-size: .85rem; color: var(--text); margin-bottom: .2rem;
}
.chat-list-item:hover { background: var(--light); text-decoration: none; }
.chat-list-item.active { background: var(--blue-soft, #DBEAFE); color: var(--blue-dark); font-weight: 600; }
.chat-list-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list-item button { background: none; border: none; color: var(--muted); cursor: pointer; padding: .2rem; flex-shrink: 0; border-radius: 4px; }
.chat-list-item button:hover { color: var(--red); background: var(--red-soft); }
.chat-list-item button svg { width: 14px; height: 14px; display: block; }
.chat-empty-list { padding: 1rem .6rem; font-size: .82rem; color: var(--muted); }

.chat-main { flex: 1; display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.chat-bubble-row { display: flex; }
.chat-bubble-row.user { justify-content: flex-end; }
.chat-bubble { max-width: 72%; padding: .7rem 1rem; border-radius: 14px; font-size: .9rem; white-space: pre-wrap; line-height: 1.5; }
.chat-bubble-row.user .chat-bubble { background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble-row.assistant .chat-bubble { background: var(--light); color: var(--text); border-bottom-left-radius: 4px; }
.chat-feedback { display: flex; gap: .3rem; margin-top: .35rem; }
.chat-feedback button {
  background: none; border: 1px solid var(--border); border-radius: 6px; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted);
}
.chat-feedback button svg { width: 14px; height: 14px; }
.chat-feedback button.active-util { background: var(--green-soft); border-color: var(--green); color: #166534; }
.chat-feedback button.active-nao_util { background: var(--red-soft); border-color: var(--red); color: #991B1B; }
.chat-input-bar { border-top: 1px solid var(--border); padding: .9rem; display: flex; gap: .5rem; }
.chat-input-bar input { flex: 1; }
.chat-empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; color: var(--muted); }

.chat-shell-3col { align-items: stretch; }
.chat-main-head { display: flex; align-items: center; gap: .6rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); font-size: .92rem; }
.chat-side-panel { width: 220px; flex-shrink: 0; overflow-y: auto; }
.chat-quick-row { display: flex; gap: .4rem; flex-wrap: wrap; padding: .75rem .9rem 0; }

.chat-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--blue-soft, #DBEAFE); color: var(--blue-dark);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-avatar svg { width: 16px; height: 16px; }
.chat-avatar-sm { width: 24px; height: 24px; }
.chat-avatar-sm svg { width: 13px; height: 13px; }
.chat-avatar-user { background: var(--navy); color: #fff; }
.chat-bubble-row { gap: .6rem; align-items: flex-start; }
.chat-bubble-row.user { align-items: flex-start; }

.chip-quick {
  background: var(--light); border: 1px solid var(--border); border-radius: 999px;
  padding: .4rem .85rem; font-size: .8rem; color: var(--text); cursor: pointer;
}
.chip-quick:hover { background: var(--border); }
.chip-quick:disabled { color: var(--muted); cursor: not-allowed; }

.ia-capacidades { list-style: none; margin: 0; padding: 0; }
.ia-capacidades li { display: flex; align-items: flex-start; gap: .5rem; font-size: .84rem; margin-bottom: .5rem; }
.ia-capacidades li svg { width: 14px; height: 14px; color: var(--green); flex-shrink: 0; margin-top: .15rem; }

@media (max-width: 1100px) {
  .chat-shell-3col { flex-direction: column; height: auto; }
  .chat-side-panel { width: 100%; }
}
.chat-empty-state svg { width: 40px; height: 40px; color: var(--muted); opacity: .5; margin-bottom: 1rem; }
