:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --sidebar-bg: #111827;
    --sidebar-hover: #1f2937;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 10px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* Auth Page */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    padding: 20px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.auth-logo h1 { margin: 0; font-size: 20px; }
.auth-logo p { margin: 0; color: var(--muted); font-size: 12px; }
.auth-card h2 { margin: 0 0 6px; font-size: 18px; }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.auth-form .form-group { margin-bottom: 14px; }

.logo-badge {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    flex-shrink: 0;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 14px;
}
.brand-title { font-weight: 700; font-size: 15px; color: #fff; }
.brand-sub { font-size: 11px; color: #9ca3af; }

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}
.nav-item {
    border: none;
    background: transparent;
    color: #d1d5db;
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.user-pill { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: #374151; color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-role { font-size: 11px; color: #9ca3af; }

.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 58px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h2 { margin: 0; font-size: 17px; }
.mobile-menu-btn { display: none; }

.content-body { padding: 22px 24px; flex: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards & Grids */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 18px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.card-header h3 { margin: 0; font-size: 15px; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi-grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 700; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

.two-col-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 18px;
}

/* Forms & Inputs */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-group label { font-size: 12px; font-weight: 600; color: #374151; }
input[type="text"], input[type="password"], input[type="number"], input[type="email"],
input[type="url"], input[type="search"], input[type="date"], input[type="month"],
select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.inline-inputs { display: flex; align-items: center; gap: 6px; }
.stack-form { display: flex; flex-direction: column; gap: 4px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Buttons */
.btn {
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #f3f4f6; color: var(--text); border-color: #d1d5db; }
.btn-secondary:hover:not(:disabled) { background: #e5e7eb; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.sidebar .btn-ghost { color: #d1d5db; border: 1px solid rgba(255, 255, 255, 0.15); }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.toolbar-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; flex: 1; }
.toolbar-filters input[type="search"] { max-width: 280px; }
.toolbar-filters select, .toolbar-filters input[type="month"] { width: auto; min-width: 130px; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
    text-align: left;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f9fafb; white-space: nowrap; }
tr:hover td { background: #f9fafb; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--muted); }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: #e5e7eb;
    color: #374151;
    white-space: nowrap;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }

/* Image Studio */
.image-controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    cursor: pointer;
    background: #f8fafc;
    transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover { border-color: var(--primary); background: #eff6ff; }
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 16px;
}
.img-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.img-card img {
    width: 100%;
    height: 160px;
    object-fit: contain;
    background: #f3f4f6;
    border-radius: 6px;
}
.img-meta { font-size: 12px; color: var(--muted); word-break: break-all; }

/* Modal & Alerts & Toast */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; z-index: 1000;
}
.modal-card {
    width: 100%; max-width: 560px;
    background: #fff; border-radius: 12px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #fee2e2; color: #991b1b; }

.toast {
    position: fixed; right: 20px; bottom: 20px;
    background: #111827; color: #fff;
    padding: 10px 16px; border-radius: 8px;
    font-size: 13px; opacity: 0; pointer-events: none;
    transition: opacity 0.2s; z-index: 1100;
}
.toast.show { opacity: 1; }

/* Subtabs & Influencer Templates */
.subtab-bar {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.subtab-btn {
    border: 1px solid var(--border);
    background: #f9fafb;
    color: var(--text);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.subtab-btn:hover { background: #eef2ff; border-color: #c7d2fe; }
.subtab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
}
.template-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.template-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}
.template-card-title { font-weight: 600; font-size: 14px; }
.template-subject {
    font-size: 12px;
    color: var(--muted);
    background: #f9fafb;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.template-body {
    margin: 0;
    font-family: inherit;
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
    flex: 1;
}

@media (max-width: 820px) {
    .sidebar {
        position: fixed; left: -250px; top: 0; bottom: 0; z-index: 900;
        transition: left 0.2s;
    }
    .sidebar.open { left: 0; }
    .mobile-menu-btn { display: inline-flex; }
    .topbar { padding: 0 14px; height: 52px; }
    .content-body { padding: 12px; }
    .card { padding: 14px; margin-bottom: 12px; }
    .toolbox-card { padding: 8px !important; margin-bottom: 0; }
    #toolboxFrame { height: calc(100dvh - 132px) !important; min-height: 500px !important; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi-value { font-size: 18px; }
    .two-col-grid { grid-template-columns: 1fr; gap: 12px; }
    .form-grid-2 { grid-template-columns: 1fr; }
    .toolbar-filters input[type="search"] { max-width: 100%; }
}
@media (max-width: 420px) {
    .kpi-grid { grid-template-columns: 1fr; }
}
