/* ===========================================================================
   Instagram Automation — Admin UI
   Clean, modern SaaS admin. Custom CSS, no framework dependency.
   =========================================================================== */

:root {
    --bg:          #f4f5f9;
    --surface:     #ffffff;
    --surface-2:   #fafbfd;
    --border:      #e6e8ef;
    --border-2:    #eef0f6;
    --text:        #1c2333;
    --text-soft:   #5a6478;
    --muted:       #8a93a6;

    --brand:       #6d5efc;
    --brand-600:   #5a4bf0;
    --brand-700:   #4a3dd6;
    --brand-tint:  #eef0ff;

    --ok:          #12a670;
    --ok-tint:     #e4f6ee;
    --warn:        #d9822b;
    --warn-tint:   #fbeee0;
    --danger:      #dc3545;
    --danger-tint: #fce8ea;
    --info:        #2b78d9;
    --info-tint:   #e5eefb;

    --radius:      12px;
    --radius-sm:   9px;
    --shadow-sm:   0 1px 2px rgba(20, 26, 51, .05);
    --shadow:      0 4px 16px rgba(20, 26, 51, .07);
    --sidebar-w:   248px;
    --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: #171a2b;
    color: #c7ccdb;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 18px;
    font-weight: 700;
    color: #fff;
    font-size: 15px;
}
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #f9508a, #a03cf0 55%, #6d5efc);
    color: #fff;
    flex-shrink: 0;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.07); }

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #b7bdd0;
    font-weight: 500;
    font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.nav-icon { flex-shrink: 0; opacity: .95; }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 62px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.page-title { font-size: 18px; font-weight: 650; margin: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.admin-chip {
    background: var(--brand-tint);
    color: var(--brand-700);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.icon-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-soft); padding: 6px; border-radius: 8px;
    display: none;
}
.icon-btn:hover { background: var(--border-2); }

.content { padding: 24px; flex: 1; max-width: 1180px; width: 100%; }
.app-foot {
    padding: 16px 24px;
    color: var(--muted);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--border);
}

.scrim {
    display: none;
    position: fixed; inset: 0;
    background: rgba(10,12,20,.45);
    z-index: 30;
}

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 30px; font-weight: 720; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { color: var(--text-soft); font-size: 13px; margin-top: 4px; }
.tone-brand { color: var(--brand-600); }
.tone-ok { color: var(--ok); }
.tone-info { color: var(--info); }
.tone-warn { color: var(--warn); }

/* ---------- Panels ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.panel-head h2 { font-size: 15px; font-weight: 650; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.stack > .panel:last-child { margin-bottom: 0; }

.page-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-2);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table-accounts td { white-space: nowrap; }

.row-actions { display: flex; gap: 12px; align-items: center; }
.inline { display: inline; margin: 0; }
.link {
    background: none; border: none; padding: 0; cursor: pointer;
    color: var(--brand-600); font: inherit; font-weight: 500;
}
.link:hover { text-decoration: underline; }
.link-danger { color: var(--danger); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}
.badge-ok { background: var(--ok-tint); color: var(--ok); }
.badge-warn { background: var(--warn-tint); color: var(--warn); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-info { background: var(--info-tint); color: var(--info); }
.badge-muted { background: #eef0f4; color: var(--muted); }

/* ---------- Empty states ---------- */
.empty {
    text-align: center;
    padding: 36px 20px;
    color: var(--text-soft);
}
.empty p { margin: 4px 0; }

/* ---------- CTA panel ---------- */
.cta-panel {
    background: linear-gradient(120deg, #f4f2ff, #fdeef6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.cta-panel h3 { margin: 0 0 4px; }
.cta-panel p { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
    min-height: 42px;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-primary:disabled { background: #c4c1e8; cursor: not-allowed; }
.btn-secondary { background: var(--brand-tint); color: var(--brand-700); }
.btn-secondary:hover { background: #e2e5ff; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.form-panel { max-width: 900px; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.req { color: var(--danger); }
.field input, .field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(109,94,252,.15);
}
.hint { font-size: 12px; color: var(--muted); }
.form-foot { display: flex; gap: 10px; margin-top: 22px; }

.status-readout {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-2);
    font-size: 13px;
    color: var(--text-soft);
    align-items: center;
}

.toggle-row { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 8px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input {
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
}

/* ---------- Detail grid ---------- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 24px;
}
.detail-grid > div { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.detail-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.code-block {
    background: #12141f;
    color: #d6dbe8;
    padding: 16px 18px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    margin: 0;
    white-space: pre;
}

/* ---------- Pager ---------- */
.pager { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.pager-info { color: var(--muted); font-size: 13px; }

/* ---------- Notices ---------- */
.notice {
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}
.notice a { font-weight: 600; }
.notice-ok { background: var(--ok-tint); color: #0b7a52; border-color: #bfe7d5; }
.notice-warn { background: var(--warn-tint); color: #9a5a12; border-color: #f0d6b4; }
.notice-danger { background: var(--danger-tint); color: #a51d2a; border-color: #f2c2c8; }
.notice-info { background: var(--info-tint); color: #1c5aa8; border-color: #c3d9f5; }

/* ---------- Auth / install ---------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(1200px 600px at 20% -10%, #efeaff 0%, transparent 60%),
                radial-gradient(1000px 500px at 100% 0%, #ffe9f4 0%, transparent 55%),
                var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 30px 28px;
    width: 100%;
    max-width: 400px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 13px; }
.auth-brand h1 { margin: 0 0 4px; font-size: 22px; }
.auth-brand p { margin: 0; }
.section-label { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }

.check-list { list-style: none; padding: 0; margin: 0 0 16px; }
.check-list li { padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--border-2); }
.check-list li.ok { color: #0b7a52; }
.check-list li.bad { color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .icon-btn { display: inline-flex; }
    .scrim.show { display: block; }
    .content { padding: 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
    .stat-grid { grid-template-columns: 1fr; }
    .app-foot { flex-direction: column; gap: 4px; }
}
