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

:root {
    --bg: #f5f7fc;
    --surface: #ffffff;
    --surface-2: #fafbff;
    --border: #e9edf5;
    --text: #18213a;
    --muted: #7b86a1;
    --primary: #6366f1;
    --primary-2: #8b5cf6;
    --primary-d: #4f46e5;
    --green: #16a34a;
    --amber: #d08700;
    --red: #e11d48;
    --ink: #0e1426;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 56, .06);
    --shadow: 0 2px 6px rgba(16, 24, 56, .05), 0 14px 40px rgba(16, 24, 56, .07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.lucide, [data-lucide] { width: 18px; height: 18px; stroke-width: 2; vertical-align: middle; flex-shrink: 0; }

/* ============================================================ Sidebar */
.sidebar {
    width: 250px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 50;
    overflow-y: auto;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    color: #c7cee0;
    background:
        radial-gradient(120% 60% at 0% 0%, #1b2452 0%, transparent 55%),
        linear-gradient(180deg, #11163a 0%, #0c1030 100%);
    border-right: 1px solid rgba(255, 255, 255, .06);
}
.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 800; font-size: 18px; letter-spacing: -.4px;
    color: #fff; padding: 8px 12px 22px;
}
.brand .lucide { width: 24px; height: 24px; color: var(--primary-2); }
.nav-links { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar a {
    display: flex; align-items: center; gap: 12px;
    text-decoration: none; color: #aab2cc; font-weight: 600; font-size: 14px;
    padding: 11px 14px; border-radius: 12px;
    transition: background .15s, color .15s, transform .05s;
}
.sidebar a .lucide { color: #7a83a6; transition: color .15s; }
.sidebar a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.sidebar a:hover .lucide { color: #c7cee0; }
.sidebar a.active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 8px 20px rgba(99, 102, 241, .4);
}
.sidebar a.active .lucide { color: #fff; }
.nav-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; margin-top: 10px; }
.nav-foot .user { display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: #8b93b3; font-weight: 600; }
.logout { color: #aab2cc !important; }

/* ============================================================ Content */
.content { margin-left: 250px; min-width: 0; padding: 38px 46px; }
h1 { margin: 0 0 26px; font-size: 28px; font-weight: 800; letter-spacing: -.7px; }
h2 { margin: 36px 0 16px; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 9px; letter-spacing: -.3px; }
h3 { margin: 0 0 16px; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
h2 .lucide, h3 .lucide { color: var(--primary); }

/* ============================================================ Hero */
.hero {
    display: flex; align-items: center; justify-content: space-between; gap: 18px;
    color: #fff; border-radius: 22px; padding: 28px 32px; margin-bottom: 26px;
    background:
        radial-gradient(120% 140% at 100% 0%, rgba(255,255,255,.18) 0%, transparent 45%),
        linear-gradient(120deg, #6366f1, #8b5cf6 55%, #a855f7);
    box-shadow: 0 18px 40px rgba(99, 102, 241, .32);
}
.hero-hi { font-size: 23px; font-weight: 800; letter-spacing: -.5px; }
.hero-sub { opacity: .92; margin-top: 4px; font-weight: 500; }
.hero-cta {
    display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
    background: rgba(255, 255, 255, .16); color: #fff; text-decoration: none; font-weight: 700;
    padding: 12px 20px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .35);
    transition: background .15s, transform .05s;
}
.hero-cta:hover { background: rgba(255, 255, 255, .26); }
.hero-cta:active { transform: translateY(1px); }

/* ============================================================ Flash */
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px;
    border: 1px solid transparent; font-weight: 600;
}
.flash-success { background: #e9f9f0; color: #11713f; border-color: #c2ecd3; }
.flash-error   { background: #fdeaf0; color: #b21341; border-color: #f6c9d8; }
.flash a { color: inherit; text-decoration: underline; }

/* ============================================================ Cards */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.card {
    display: flex; align-items: center; gap: 16px; min-width: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
    transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 14px 36px rgba(16, 24, 56, .12); }
.card-ic { width: 50px; height: 50px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; }
.card-ic .lucide { width: 24px; height: 24px; }
.ic-blue   { background: #eef0ff; color: var(--primary); }
.ic-violet { background: #f4ecff; color: var(--primary-2); }
.ic-green  { background: #e7f8ef; color: var(--green); }
.ic-grey   { background: #eef1f7; color: var(--muted); }
.card-num { font-size: 23px; font-weight: 800; letter-spacing: -.5px; }
.card-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.card-link { margin-left: auto; color: var(--muted); display: grid; place-items: center; text-decoration: none; }
.card-link:hover { color: var(--primary); }

.card-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin-bottom: 22px;
}

/* ============================================================ Forms */
.form { display: flex; flex-direction: column; }
.form.card-box { margin-bottom: 0; }
label { font-weight: 600; margin: 14px 0 6px; font-size: 13px; color: #41496a; }
input, select, textarea {
    width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font: inherit; background: var(--surface-2); color: var(--text); transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); background: #fff;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, .14);
}
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.input-icon { position: relative; }
.input-icon .lucide { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon input { padding-left: 42px; }

button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    margin-top: 18px; padding: 12px 20px; border: none; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
    font: inherit; font-weight: 700; cursor: pointer; align-self: flex-start;
    box-shadow: 0 8px 20px rgba(99, 102, 241, .3); transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.06); }
button:active { transform: translateY(1px); }
button:disabled { background: #c2c9da; box-shadow: none; cursor: not-allowed; }
.btn-danger { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 8px 20px rgba(225, 29, 72, .28); }
.btn-soft { margin: 0; padding: 9px 16px; background: #eef0ff; color: var(--primary-d); box-shadow: none; }
.btn-soft:hover { background: #e2e5ff; filter: none; }
.btn-link-danger { background: none; color: var(--muted); padding: 7px; margin: 0; border: none; box-shadow: none; border-radius: 9px; cursor: pointer; }
.btn-link-danger:hover { background: #fdeaf0; color: var(--red); filter: none; }

details.card-box summary { cursor: pointer; font-weight: 700; display: flex; align-items: center; gap: 8px; list-style: none; }
details.card-box summary::-webkit-details-marker { display: none; }
details.card-box summary .lucide { color: var(--primary); }
details.card-box[open] summary { margin-bottom: 18px; }

/* ============================================================ Tables */
.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 30px 0 14px; }
.table-head form { margin: 0; }
.table-head button { margin: 0; }
.th-actions { display: flex; gap: 10px; }
.th-actions form { margin: 0; }
table {
    width: 100%; border-collapse: collapse; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
th, td { text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
th { background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td form { margin: 0; }

.muted { color: var(--muted); }
.ok { color: var(--green); font-weight: 700; }
.err { color: var(--red); }

.badge { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #eef1f7; color: var(--muted); }
.badge-approved, .badge-done, .badge-available { background: #e7f8ef; color: #11713f; }
.badge-pending, .badge-submitted, .badge-in_review, .badge-running, .badge-limited { background: #fff4e0; color: #97600a; }
.badge-rejected, .badge-disabled, .badge-paused, .badge-blocked { background: #fdeaf0; color: #b21341; }
.badge-unknown { background: #eef1f7; color: var(--muted); }

/* ============================================================ Health / entities */
.health-banner {
    display: flex; align-items: center; gap: 14px; padding: 18px 22px; margin-bottom: 18px;
    border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.health-banner .lucide { width: 26px; height: 26px; flex-shrink: 0; }
.health-title { font-weight: 800; font-size: 16px; }
.health-available { background: #f0fbf5; border-color: #c8efd9; } .health-available .lucide { color: var(--green); }
.health-limited { background: #fffaf0; border-color: #f6e4bd; } .health-limited .lucide { color: var(--amber); }
.health-blocked { background: #fdf1f5; border-color: #f6c9d8; } .health-blocked .lucide { color: var(--red); }
.health-unknown .lucide { color: var(--muted); }
.entities { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.entity { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.entity-head { display: flex; align-items: center; gap: 12px; }
.entity-ic { width: 40px; height: 40px; border-radius: 11px; background: #eef0ff; color: var(--primary); display: grid; place-items: center; flex-shrink: 0; }
.entity-type { font-weight: 700; }
.entity-id { font-size: 12.5px; }
.entity-head .badge { margin-left: auto; }
.entity-note { display: flex; align-items: flex-start; gap: 9px; margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.45; }
.entity-note .lucide { width: 16px; height: 16px; margin-top: 1px; flex-shrink: 0; }
.note-warn { background: #fffaf0; color: #8a6300; }
.note-err  { background: #fdf1f5; color: #b21341; }

/* ============================================================ Progress / stats */
.progress { height: 14px; background: #eceffa; border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 999px; transition: width .4s ease; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; text-align: center; }
.stat-num { display: block; font-size: 25px; font-weight: 800; letter-spacing: -.5px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.stat-ok .stat-num { color: var(--green); }
.stat-err .stat-num { color: var(--red); }
.stat-pending .stat-num { color: var(--amber); }
#bcDone { margin-top: 16px; } #bcDone a { color: var(--primary); font-weight: 700; }

/* ============================================================ JSON / code */
.json {
    background: #0e1426; color: #c4cef0; border-radius: var(--radius); padding: 20px;
    max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
    font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; box-shadow: var(--shadow);
}
code { background: #eef1f7; padding: 1px 7px; border-radius: 6px; font-size: 12.5px; font-family: ui-monospace, monospace; }
.raw-json { margin-top: 18px; }
.raw-json summary { cursor: pointer; color: var(--muted); font-weight: 700; }
.raw-json .json { margin-top: 12px; }

/* ============================================================ Pagination */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0 4px; }
.pg-btn {
    display: inline-flex; align-items: center; gap: 6px; margin: 0;
    padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px;
    text-decoration: none; cursor: pointer; box-shadow: none;
}
.pg-btn:hover:not(.disabled):not(:disabled) { background: var(--surface-2); border-color: var(--primary); color: var(--primary); filter: none; }
.pg-btn.disabled, .pg-btn:disabled { opacity: .45; pointer-events: none; }
.pg-info { color: var(--muted); font-size: 13px; font-weight: 500; }

/* ============================================================ Sync bar */
.sync-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
.sync-bar form { margin: 0; }
.sync-bar .muted { display: inline-flex; align-items: center; gap: 6px; }

/* ============================================================ Contact groups */
.group-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 22px; }
.group-pill {
    display: inline-flex; align-items: center; gap: 7px; text-decoration: none; font-weight: 600; font-size: 13px;
    background: var(--surface); border: 1px solid var(--border); color: #41496a; padding: 8px 15px; border-radius: 999px;
    transition: background .15s, color .15s, border-color .15s;
}
.group-pill:hover { background: var(--surface-2); }
.group-pill.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(99,102,241,.3); }
.group-cnt { background: rgba(0, 0, 0, .08); border-radius: 999px; padding: 0 7px; font-size: 11px; }
.group-pill.active .group-cnt { background: rgba(255, 255, 255, .25); }
.group-create { display: flex; gap: 6px; margin: 0; }
.group-create input { width: 150px; padding: 8px 12px; }
.group-create button { margin: 0; padding: 8px 12px; }
.bc-vars { margin-top: 6px; }
.var-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.var-row .var-tag { font-family: ui-monospace, monospace; font-weight: 700; color: var(--primary); background: #eef0ff; padding: 6px 9px; border-radius: 8px; flex-shrink: 0; }
.var-row select { width: 150px; flex-shrink: 0; }
.var-row input { flex: 1; }
.spinner-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); margin-right: 6px; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* ============================================================ Business profile card */
.profile-card { display: flex; align-items: center; gap: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.profile-meta { flex: 1; min-width: 0; }
.profile-about { font-weight: 700; font-size: 16px; }
.profile-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; background: #eef1f7; color: #41496a; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .lucide { width: 14px; height: 14px; color: var(--primary); flex-shrink: 0; }
.avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); flex-shrink: 0; }
.avatar-empty { display: grid; place-items: center; background: #eef0ff; color: var(--primary); }
.avatar-empty .lucide { width: 30px; height: 30px; }
.avatar-row { display: flex; gap: 16px; align-items: center; }

/* ============================================================ Template view + preview */
.tpl-link { color: var(--primary); text-decoration: none; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.tpl-link:hover { text-decoration: underline; }
table.kv { box-shadow: none; border: none; }
table.kv td { border: none; padding: 6px 0; vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 120px; font-weight: 600; }
.wa-preview { background: #d9e7d6; border-radius: var(--radius); padding: 18px; background-image: radial-gradient(rgba(0,0,0,.03) 1px, transparent 1px); background-size: 14px 14px; }
.wa-bubble { background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: 0 2px 4px rgba(0,0,0,.12); max-width: 340px; }
.wa-header { font-weight: 700; margin-bottom: 6px; }
.wa-media { display: flex; align-items: center; gap: 8px; background: #f0f2f5; border-radius: 8px; padding: 18px 12px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.wa-body { white-space: pre-wrap; word-break: break-word; }
.wa-footer { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.wa-buttons { max-width: 340px; margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.wa-btn { background: #fff; color: #1f8aff; font-weight: 700; border-radius: 8px; padding: 9px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 7px; box-shadow: 0 2px 4px rgba(0,0,0,.1); }
.wa-btn .lucide { width: 15px; height: 15px; }

/* ============================================================ Login */
.login-body { display: grid; place-items: center; background: radial-gradient(1000px 600px at 50% -10%, #2a2d6e 0%, transparent 55%), linear-gradient(160deg, #11163a, #0c1030); }
.login-card { width: 370px; background: var(--surface); border-radius: 24px; padding: 38px 34px; box-shadow: 0 30px 80px rgba(0, 0, 0, .4); text-align: center; }
.login-logo { width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 18px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); display: grid; place-items: center; box-shadow: 0 12px 28px rgba(99, 102, 241, .45); }
.login-logo .lucide { width: 31px; height: 31px; color: #fff; }
.login-card h2 { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -.4px; }
.login-sub { margin: 6px 0 22px; font-size: 13px; }
.login-card .form { text-align: left; }
.login-card label { margin-top: 12px; }
.login-card button { width: 100%; margin-top: 22px; padding: 13px; }
.login-card .flash { text-align: left; }

/* ============================================================ htmx loading cue */
.htmx-request.content, .htmx-request .content { opacity: .55; transition: opacity .15s; }
#htmx-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 9999; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .2s ease; }
body.htmx-request #htmx-bar { width: 80%; }

/* ============================================================ Responsive */
@media (max-width: 820px) {
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .nav-links { flex-direction: row; flex-wrap: wrap; }
    .nav-foot { border: none; margin: 0; padding: 0; }
    .content { margin-left: 0; padding: 24px 18px; }
    .cards, .stats { grid-template-columns: 1fr; }
    .entities { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
