/* ═══════════════════════════════════════════
   Haxmax Maximize — giao diện Cài đặt
   ═══════════════════════════════════════════ */

:root {
  --bg:            #f4f5f7;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --border:        #eaecf0;
  --border-2:      #dfe3e8;
  --text:          #101828;
  --text-2:        #667085;
  --text-3:        #98a2b3;

  --brand:         #4f46e5;
  --brand-hover:   #4338ca;
  --brand-soft:    #eef0fe;
  --brand-ring:    rgba(79, 70, 229, .16);

  --green:         #16a34a;
  --green-soft:    #dcfce7;
  --red:           #ef4444;
  --red-soft:      #fee2e2;

  --shadow:        0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.05);
  --shadow-lg:     0 12px 32px rgba(16,24,40,.14);
  --radius:        14px;
  --sidebar-w:     232px;
  /* Dùng chung cho thanh header VÀ khối logo sidebar -> mép dưới luôn thẳng hàng */
  --topbar-h:      96px;
}

html[data-theme="dark"] {
  --bg:            #0e1015;
  --surface:       #161a22;
  --surface-2:     #1b202a;
  --border:        #242a36;
  --border-2:      #303845;
  --text:          #e9edf5;
  --text-2:        #949eb0;
  --text-3:        #6b7688;

  --brand:         #7c74f5;
  --brand-hover:   #8f88f7;
  --brand-soft:    #23223d;
  --brand-ring:    rgba(124, 116, 245, .22);

  --green:         #4ade80;
  --green-soft:    #12301f;
  --red:           #f87171;
  --red-soft:      #351a1a;

  --shadow:        0 1px 2px rgba(0,0,0,.4);
  --shadow-lg:     0 12px 32px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

h1, h2 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; }

.ico {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

/* ─────────── Sidebar ─────────── */
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform .25s ease, background .2s ease;
}

.brand {
  height: var(--topbar-h);          /* bằng đúng chiều cao header bên phải */
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  padding: 0 18px;
}
.brand-logo {
  width: 84px; max-width: 100%; height: auto;
  display: block;
  transition: filter .2s ease;
}
/* Wordmark là xanh navy đậm — cần sáng lên ở chế độ tối */
html[data-theme="dark"] .brand-logo { filter: brightness(2.3) saturate(1.1); }

.brand-sub {
  font-size: 10px; font-weight: 800;
  letter-spacing: .18em; text-transform: uppercase;
  background: linear-gradient(90deg, #3b82f6, #a855f7);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.nav { padding: 14px 12px 0; display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--text-2);
}
.social { display: flex; gap: 12px; }
.social a { color: var(--text-3); display: grid; place-items: center; transition: color .15s; }
.social a:hover { color: var(--brand); }
.social svg { width: 17px; height: 17px; }

.scrim {
  position: fixed; inset: 0; background: rgba(16,24,40,.45);
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 35;
}

/* ─────────── Shell / topbar ─────────── */
.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }

.user-email {
  font-size: 13.5px; color: var(--text-2);
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.burger { display: none; border-radius: 10px; }

.ico-sun { display: none; }
html[data-theme="dark"] .ico-moon { display: none; }
html[data-theme="dark"] .ico-sun  { display: block; }

/* ─────────── Buttons ─────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .ico { width: 17px; height: 17px; }

.btn-ghost   { background: var(--surface); border-color: var(--border-2); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn-outline { background: transparent; border-color: var(--border-2); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); border-color: var(--brand); color: var(--brand); }

.btn-danger-ghost { background: transparent; color: var(--red); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--red-soft); }

/* ─────────── Page ─────────── */
.page { flex: 1; padding: 34px 22px 64px; }
.container { max-width: 940px; margin: 0 auto; }

.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }
.page-head h1 { font-size: 26px; }
.page-head p { color: var(--text-2); margin-top: 3px; }

.tile {
  width: 40px; height: 40px; flex: none;
  border-radius: 11px;
  display: grid; place-items: center;
}
.tile-lg { width: 50px; height: 50px; border-radius: 14px; }
.tile-lg .ico { width: 24px; height: 24px; }
.tile-indigo { background: var(--brand-soft); color: var(--brand); }
.tile-red    { background: var(--red-soft);   color: var(--red); }

/* Tile cho logo thương hiệu (icon dạng fill, không phải stroke) */
.ico-brand {
  width: 20px; height: 20px; flex: none;
  fill: currentColor; stroke: none;
}
.tile-claude { background: #fbebe3; color: #d97757; }   /* cam đất Anthropic */
.tile-mono   { background: #eef0f4; color: #0d0f14; }   /* OpenAI & ElevenLabs — đen */
.tile-gemini { background: #eaf1fe; color: #4285f4; }   /* Google Gemini */

html[data-theme="dark"] .tile-claude { background: #33241c; color: #e59372; }
html[data-theme="dark"] .tile-mono   { background: #22262f; color: #eef1f6; }
html[data-theme="dark"] .tile-gemini { background: #1b2436; color: #7aa5f7; }

/* ─────────── Cards ─────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
  transition: border-color .18s, box-shadow .18s, background .2s;
}
.card:hover { border-color: var(--border-2); }
.card.is-open { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

.card-head {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  padding: 17px 20px;
  background: none; border: 0;
  text-align: left; cursor: pointer;
  color: inherit;
}
.card-head.is-static { cursor: default; }
.card-title { flex: 1; min-width: 0; }
.card-title h2 {
  font-size: 15px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
}
.card-title p { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.chev { color: var(--text-3); transition: transform .22s ease; }
.card.is-open .chev { transform: rotate(180deg); }

.card-body {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .26s ease;
}
.card.is-open .card-body { grid-template-rows: 1fr; }
.card-body > .body-inner { overflow: hidden; }
.body-inner > * { border-top: 1px solid var(--border); padding: 20px; }

/* ─────────── Info rows ─────────── */
.rows { border-top: 1px solid var(--border); }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 20px;
}
.row + .row { border-top: 1px solid var(--border); }
.row-k { color: var(--text-2); font-size: 13.5px; }
.row-v { font-weight: 600; font-size: 13.5px; word-break: break-all; text-align: right; }
.text-green { color: var(--green); }

/* ─────────── Badges ─────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  white-space: nowrap;
}
.badge-indigo { background: var(--brand-soft); color: var(--brand); }
.badge-green  { background: var(--green-soft); color: var(--green); }
.badge-gray   { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }

/* ─────────── Forms ─────────── */
.form { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.opt { font-weight: 500; color: var(--text-3); }
.hint { font-size: 12px; color: var(--text-3); }

input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-2);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
  background: var(--surface);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}

.input-wrap { position: relative; }
.input-wrap input { padding-right: 42px; }
.reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0; background: none; color: var(--text-3);
  border-radius: 7px; cursor: pointer;
  transition: color .15s, background .15s;
}
.reveal:hover { color: var(--text); background: var(--surface-2); }
.reveal::before {
  content: "";
  width: 18px; height: 18px;
  background: currentColor;
  -webkit-mask: var(--eye) center / contain no-repeat;
  mask: var(--eye) center / contain no-repeat;
}
.reveal { --eye: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z'/><circle cx='12' cy='12' r='3'/></svg>"); }
.reveal.is-on { --eye: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-10-8-10-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 10 8 10 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24'/><path d='m1 1 22 22'/></svg>"); color: var(--brand); }

.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 2px; }
.test-result { font-size: 12.5px; font-weight: 600; }
.test-result.ok   { color: var(--green); }
.test-result.err  { color: var(--red); }
.test-result.wait { color: var(--text-2); }

.page-foot { text-align: center; color: var(--text-3); font-size: 12.5px; margin-top: 26px; }

/* ─────────── Trang đăng nhập ─────────── */
.auth-body { background: var(--bg); }
.auth-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 16px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 28px 26px;
  display: flex; flex-direction: column; align-items: center;
}
.auth-logo { width: 112px; height: auto; display: block; }
html[data-theme="dark"] .auth-logo { filter: brightness(2.3) saturate(1.1); }

.auth-title { font-size: 20px; margin-top: 22px; }
.auth-sub {
  color: var(--text-2); font-size: 13px;
  margin-top: 5px; margin-bottom: 22px; text-align: center;
}
.auth-card .form { width: 100%; gap: 14px; }

.btn-block { width: 100%; justify-content: center; padding: 10px 15px; }

.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-2); cursor: pointer;
}
.check input { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }

.auth-error {
  color: var(--red); font-size: 13px; font-weight: 600;
  text-align: center; min-height: 19px; margin: 0;
}

/* ─────────── Toasts ─────────── */
.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 250px; max-width: 360px;
  padding: 12px 15px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--brand);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 500;
  animation: toast-in .25s ease;
}
.toast.ok  { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.out { animation: toast-out .22s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(16px); } }

/* ─────────── Responsive ─────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .shell { margin-left: 0; }
  .burger { display: grid; }
  .user-email { display: none; }
}
@media (max-width: 620px) {
  .page { padding: 24px 14px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card-head { padding: 15px; gap: 12px; }
  .page-head h1 { font-size: 22px; }
  .btn span { display: inline; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
}
