@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,700;1,9..144,400&family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --white:   #ffffff;
  --bg:      #f7f7f5;
  --surface: #f2f2ef;
  --border:  #e8e8e4;
  --border2: #d4d4ce;
  --ink:     #1a1a18;
  --ink2:    #3d3d38;
  --muted:   #7a7a72;
  --muted2:  #b0b0a6;
  --green:   #25d366;  /* WhatsApp green */
  --green-d: #1db954;
  --green-l: #dcfce7;
  --green-b: #bbf7d0;
  --red:     #dc2626;
  --red-l:   #fee2e2;
  --amber:   #e8920a;
  --amber-l: #fef3e0;
  --amber-b: #fde8b8;
  --blue:    #2563eb;
  --blue-l:  #dbeafe;
  --font:    'Outfit', sans-serif;
  --serif:   'Fraunces', serif;
  --mono:    'JetBrains Mono', monospace;
  --sidebar: 256px;
  --topbar:  60px;
  --r:       12px;
  --r-lg:    18px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 12px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }

/* ── APP SHELL ── */
.app-body { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar); background: var(--white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  z-index: 200; transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.sidebar-top { padding: 1.4rem 1.2rem 1rem; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .65rem; }
.brand-icon {
  width: 38px; height: 38px;
  background: var(--green); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
  box-shadow: 0 4px 12px rgba(37,211,102,.3);
}
.brand-name { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--ink); }
.brand-version { font-size: .62rem; font-family: var(--mono); color: var(--muted2); }

.nav-section { flex: 1; overflow-y: auto; padding: .9rem .8rem; }
.nav-label { font-size: .62rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted2); padding: .4rem .5rem; margin-bottom: .2rem; margin-top: .6rem; }
.nav-label:first-child { margin-top: 0; }
.nav-item { display: flex; align-items: center; gap: .65rem; padding: .55rem .75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .86rem; font-weight: 500; margin-bottom: 1px; transition: background .12s, color .12s; }
.nav-item:hover { background: var(--surface); color: var(--ink2); }
.nav-item.active { background: var(--green); color: #fff; font-weight: 600; }
.nav-ico { font-size: .9rem; width: 18px; text-align: center; flex-shrink: 0; }
.nav-badge { margin-left: auto; background: var(--green); color: #fff; font-size: .6rem; font-weight: 700; font-family: var(--mono); padding: .1rem .38rem; border-radius: 20px; }

.sidebar-footer { padding: .9rem 1rem; border-top: 1px solid var(--border); }
.user-row { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; margin-bottom: .6rem; }
.user-ava { width: 30px; height: 30px; background: var(--green); border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: .8rem; flex-shrink: 0; }
.user-name { font-size: .82rem; font-weight: 600; color: var(--ink); }
.user-role { font-size: .65rem; color: var(--muted); font-family: var(--mono); }
.logout-btn { width: 100%; padding: .5rem; border-radius: 8px; border: 1px solid var(--border); background: transparent; font-family: var(--font); font-size: .8rem; font-weight: 500; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: .4rem; transition: all .12s; }
.logout-btn:hover { border-color: var(--red); color: var(--red); background: var(--red-l); }

/* ── MAIN ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: var(--topbar); background: var(--white); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 1.6rem; gap: 1rem; flex-shrink: 0; }
.topbar-menu { display: none; background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.topbar-title { flex: 1; }
.topbar-title h1 { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; color: var(--ink); }
.topbar-title span { font-size: .72rem; color: var(--muted); font-family: var(--mono); }
.topbar-right { display: flex; align-items: center; gap: .75rem; }

.page-content { flex: 1; overflow-y: auto; padding: 1.8rem; }

/* ── CARDS ── */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 1.2rem; animation: fadeUp .4s ease both; }
@keyframes fadeUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.card:nth-child(2){animation-delay:.05s} .card:nth-child(3){animation-delay:.1s} .card:nth-child(4){animation-delay:.15s}
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border); }
.card-head h2 { font-family: var(--serif); font-size: 1rem; font-weight: 600; color: var(--ink); }
.card-body { padding: 1.4rem; }

/* ── STATS ── */
.stats-grid { display: grid; gap: 1rem; margin-bottom: 1.4rem; }
.stats-4 { grid-template-columns: repeat(4,1fr); }
.stats-3 { grid-template-columns: repeat(3,1fr); }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 1.2rem 1.4rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; animation: fadeUp .4s ease both; }
.stat-card::after { content:''; position:absolute; bottom:0; left:0; right:0; height:3px; border-radius:0 0 var(--r-lg) var(--r-lg); }
.stat-c-green::after { background: linear-gradient(90deg, var(--green), transparent); }
.stat-c-blue::after  { background: linear-gradient(90deg, var(--blue),  transparent); }
.stat-c-amber::after { background: linear-gradient(90deg, var(--amber), transparent); }
.stat-c-red::after   { background: linear-gradient(90deg, var(--red),   transparent); }
.stat-c-ink::after   { background: linear-gradient(90deg, var(--ink),   transparent); }
.stat-label { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-bottom: .5rem; }
.stat-value { font-family: var(--serif); font-size: 2rem; font-weight: 700; color: var(--ink); line-height: 1; margin-bottom: .3rem; }
.stat-sub { font-size: .75rem; color: var(--muted); }

/* ── FORMS ── */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .74rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink2); margin-bottom: .45rem; }
.field small { display: block; font-size: .7rem; color: var(--muted); margin-top: .3rem; }
input[type=text], input[type=password], input[type=tel], input[type=url], input[type=email], input[type=search], select, textarea {
  width: 100%; background: var(--white); border: 1.5px solid var(--border); border-radius: 9px; color: var(--ink); font-family: var(--font); font-size: .88rem; padding: .65rem .95rem; transition: border-color .15s, box-shadow .15s; outline: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(37,211,102,.12); }
input::placeholder, textarea::placeholder { color: var(--muted2); }
textarea { resize: vertical; }
select { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7a72' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .9rem center; padding-right: 2.2rem; }
.field-row { display: flex; gap: .7rem; }
.field-row .field { flex: 1; margin-bottom: 0; }

/* ── BUTTONS ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .6rem 1.2rem; border-radius: 9px; font-family: var(--font); font-size: .86rem; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; text-decoration: none; transition: all .15s; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-green { background: var(--green); color: #fff; border-color: var(--green); box-shadow: 0 3px 12px rgba(37,211,102,.25); }
.btn-green:hover { background: var(--green-d); box-shadow: 0 5px 16px rgba(37,211,102,.35); transform: translateY(-1px); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: var(--ink2); }
.btn-outline { background: transparent; border-color: var(--border2); color: var(--ink2); }
.btn-outline:hover { border-color: var(--ink); color: var(--ink); background: var(--surface); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--surface); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: var(--red-l); }
.btn-full { width: 100%; }
.btn-sm { padding: .38rem .8rem; font-size: .78rem; border-radius: 7px; }
.btn-lg { padding: .8rem 1.6rem; font-size: .95rem; }
.btn-spin { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: rot .6s linear infinite; display: none; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ── ALERTS ── */
.alert { display: flex; align-items: flex-start; gap: .6rem; padding: .75rem 1rem; border-radius: 9px; font-size: .83rem; margin-bottom: 1rem; }
.alert-ico { flex-shrink: 0; font-size: 1rem; }
.alert-ok   { background: var(--green-l); border: 1px solid var(--green-b); color: #166534; }
.alert-err  { background: var(--red-l);   border: 1px solid #fecaca;        color: #991b1b; }
.alert-info { background: var(--blue-l);  border: 1px solid #bfdbfe;        color: #1e40af; }
.alert-warn { background: var(--amber-l); border: 1px solid var(--amber-b); color: #92400e; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th { text-align: left; padding: .65rem 1rem; font-size: .67rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--border); }
tbody td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); color: var(--ink2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface); }
.td-main { font-weight: 600; color: var(--ink) !important; }
.td-mono { font-family: var(--mono); font-size: .74rem !important; color: var(--muted) !important; }
.td-end  { text-align: right; }
.td-actions { display: flex; gap: .4rem; justify-content: flex-end; }

/* ── PILLS ── */
.pill { display: inline-flex; align-items: center; padding: .18rem .55rem; border-radius: 20px; font-size: .68rem; font-weight: 600; font-family: var(--mono); white-space: nowrap; }
.pill-green { background: var(--green-l); color: #166534; border: 1px solid var(--green-b); }
.pill-red   { background: var(--red-l);   color: #991b1b; border: 1px solid #fecaca; }
.pill-amber { background: var(--amber-l); color: #92400e; border: 1px solid var(--amber-b); }
.pill-blue  { background: var(--blue-l);  color: #1e40af; border: 1px solid #bfdbfe; }
.pill-muted { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.pill-ink   { background: var(--ink); color: #fff; }

/* ── DIVIDER ── */
.divider { height: 1px; background: var(--border); margin: 1.2rem 0; }

/* ── EMPTY STATE ── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; padding: 3rem 1rem; text-align: center; color: var(--muted); font-size: .85rem; }
.empty-icon { font-size: 2.5rem; opacity: .4; }
.empty-state strong { color: var(--ink2); font-size: .95rem; }

/* ── SPINNER ── */
.spinner-lg { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--green); border-radius: 50%; animation: rot .7s linear infinite; }
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── WA STATUS BADGE ── */
.wa-badge { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .75rem; border-radius: 20px; font-size: .75rem; font-weight: 600; font-family: var(--mono); }
.wa-connected    { background: var(--green-l); color: #166534; border: 1px solid var(--green-b); }
.wa-qr           { background: var(--amber-l); color: #92400e; border: 1px solid var(--amber-b); }
.wa-disconnected { background: var(--red-l);   color: #991b1b; border: 1px solid #fecaca; }
.wa-connecting   { background: var(--blue-l);  color: #1e40af; border: 1px solid #bfdbfe; }
.wa-dot { width: 7px; height: 7px; border-radius: 50%; }
.wa-connected .wa-dot    { background: #16a34a; box-shadow: 0 0 5px rgba(22,163,74,.5); }
.wa-qr .wa-dot           { background: var(--amber); }
.wa-disconnected .wa-dot { background: var(--red); }
.wa-connecting .wa-dot   { background: var(--blue); animation: pulse .8s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── CODE BLOCKS ── */
.code-block { background: var(--ink); color: #a5f3fc; border-radius: 10px; padding: 1rem 1.2rem; font-family: var(--mono); font-size: .76rem; line-height: 1.7; overflow-x: auto; position: relative; }
.code-key { color: #fde68a; } .code-str { color: #86efac; } .code-num { color: #f9a8d4; } .code-cmt { color: #6b7280; }
.copy-btn { position: absolute; top: .6rem; right: .6rem; background: rgba(255,255,255,.1); border: none; border-radius: 6px; color: rgba(255,255,255,.6); font-family: var(--font); font-size: .7rem; padding: .25rem .6rem; cursor: pointer; transition: all .12s; }
.copy-btn:hover { background: rgba(255,255,255,.2); color: #fff; }

/* ── QR BOX ── */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 1.5rem; background: var(--surface); border: 2px dashed var(--border2); border-radius: var(--r-lg); }
.qr-box img { width: 200px; height: 200px; border-radius: var(--r); border: 4px solid #fff; box-shadow: var(--shadow); }

/* SCROLLBAR */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 10px; }

/* OVERLAY */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; }

/* RESPONSIVE */
@media (max-width: 1000px) { .stats-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 768px) {
  .sidebar { position: fixed; top:0; left:0; bottom:0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar-menu { display: flex; }
  .page-content { padding: 1.2rem; }
  .stats-4,.stats-3 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 769px) { .topbar-menu { display: none !important; } }
