/* ============================================
   AutoPost Pro — Design System v2
   Modern SaaS with dark sidebar
   ============================================ */

/* Pretendard font loaded via <link> in base.html for non-blocking render */

:root {
    /* Brand */
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --primary-rgb: 59, 130, 246;

    /* Grays */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Semantic */
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --error: #ef4444;
    --error-light: #fef2f2;
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;
    --cyan: #06b6d4;
    --cyan-light: #ecfeff;

    /* Surfaces */
    --bg: var(--gray-50);
    --surface: #ffffff;
    --border: var(--gray-200);

    /* Text */
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-500);
    --text-tertiary: var(--gray-400);

    /* Sidebar */
    --sidebar-bg: var(--gray-900);
    --sidebar-width: 260px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 100px;

    /* Transition */
    --transition: 0.15s ease;

    /* Legacy compat aliases */
    --primary-color: var(--primary);
    --secondary-color: var(--primary-hover);
    --accent-color: var(--primary);
    --bg-color: var(--bg);
    --bg-secondary: var(--gray-100);
    --sidebar-bg-legacy: var(--sidebar-bg);
    --text-color: var(--text-primary);
    --border-color: var(--border);
    --success-color: var(--success);
    --warning-color: var(--warning);
    --error-color: var(--error);
    --shadow: var(--shadow-sm);
}

/* ── Reset ─────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Pretendard Variable', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Sidebar (Dark) ───────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: fixed;
    height: 100vh;
    z-index: 500;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--gray-700);
    border-radius: 4px;
}

.logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 32px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
    letter-spacing: -0.02em;
}

.logo svg {
    color: var(--primary);
    flex-shrink: 0;
}

.nav-menu {
    list-style: none;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    margin-bottom: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--gray-400);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    font-weight: 500;
    font-size: 0.875rem;
    position: relative;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--gray-200);
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.15);
    color: #ffffff;
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

.nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-link.active svg,
.nav-link:hover svg {
    opacity: 1;
}

/* Sidebar user info */
.sidebar-user {
    padding: 16px 8px 0;
    margin-top: auto;
    border-top: 1px solid var(--gray-800);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.sidebar-user .user-name {
    color: var(--gray-300);
    font-size: 0.8rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Mobile menu toggle */
.menu-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 600;
    background: var(--gray-900);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.2rem;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 400;
    backdrop-filter: blur(2px);
}

/* ── Main Content ─────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px 40px;
    min-width: 0;
    max-width: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.025em;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    padding: 6px 12px;
    background-color: var(--primary);
    color: white;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* ── Cards ─────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.card {
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-size: 1.2rem;
}

.card-icon.blue { background: var(--primary-light); color: var(--primary); }
.card-icon.green { background: var(--success-light); color: var(--success); }
.card-icon.purple { background: var(--purple-light); color: var(--purple); }
.card-icon.orange { background: var(--warning-light); color: var(--warning); }
.card-icon.cyan { background: var(--cyan-light); color: var(--cyan); }
.card-icon.red { background: var(--error-light); color: var(--error); }

/* ── Block Editor ──────────────────────── */
.editor-container {
    background: var(--surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    padding: 32px;
    box-shadow: var(--shadow-xs);
}

.block {
    position: relative;
    padding: 16px;
    margin-bottom: 12px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    transition: all var(--transition);
    background: var(--surface);
}

.block:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.08);
}

.block-controls {
    position: absolute;
    right: 8px;
    top: 8px;
    display: none;
    gap: 4px;
}

.block:hover .block-controls {
    display: flex;
}

/* ── Buttons ───────────────────────────── */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition);
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    line-height: 1;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-purple {
    background: var(--purple);
    color: white;
}

.btn-purple:hover {
    background: #7c3aed;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 12px 28px;
    font-size: 1rem;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}

.btn-ghost:hover {
    background: var(--gray-100);
    color: var(--text-primary);
    box-shadow: none;
    transform: none;
}

/* ── Status Badges ─────────────────────── */
.status-badge {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.status-published { background: var(--success-light); color: #065f46; }
.status-draft { background: var(--gray-100); color: var(--gray-600); }
.status-outline { background: #dbeafe; color: #1e40af; }
.status-review_pending { background: var(--warning-light); color: #92400e; }
.status-error { background: var(--error-light); color: #991b1b; }

/* Plan badges */
.plan-badge {
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.plan-basic { background: var(--gray-100); color: var(--gray-600); }
.plan-pro { background: var(--primary-light); color: var(--primary); }
.plan-admin { background: var(--purple-light); color: var(--purple); }

/* ── Tables ────────────────────────────── */
.table-wrapper {
    background: var(--surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    text-align: left;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--gray-50);
}

table th, table td {
    padding: 14px 16px;
}

table thead tr {
    border-bottom: 1px solid var(--border);
}

table tbody tr {
    border-bottom: 1px solid var(--gray-100);
    transition: background var(--transition);
}

table tbody tr:hover {
    background: var(--gray-50);
}

table tbody tr:last-child {
    border-bottom: none;
}

/* ── Forms ─────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
input[type="url"],
select,
textarea {
    font-family: inherit;
    font-size: 0.875rem;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    transition: all var(--transition);
    width: 100%;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-tertiary);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group {
    margin-bottom: 20px;
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Modals ────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 32px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--gray-900);
}

/* ── Alerts / Banners ──────────────────── */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.alert-info {
    background: var(--primary-light);
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-success {
    background: var(--success-light);
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: var(--error-light);
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ── Ad Block Placeholder ──────────────── */
.ad-block-placeholder {
    background: var(--warning-light);
    border: 1.5px dashed var(--warning);
    color: #92400e;
    padding: 20px;
    text-align: center;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
}

/* ── Loading / Spinner ─────────────────── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-lg {
    width: 32px;
    height: 32px;
}

/* ── Progress Bar ──────────────────────── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

/* ── Empty State ───────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    color: var(--gray-300);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.875rem;
    margin-bottom: 20px;
}

/* ── Tabs ──────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 28px;
    overflow-x: auto;
}

.tab {
    padding: 12px 20px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    transition: color var(--transition);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--primary);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ── Section Divider ───────────────────── */
.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-100);
}

/* ── Tooltip ───────────────────────────── */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: white;
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.tooltip:hover::after {
    opacity: 1;
}

/* ── Responsive ────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 16px;
    }

    .main-content {
        padding: 24px;
    }
}

@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 64px;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .editor-container {
        padding: 16px;
    }

    .editor-actions {
        flex-direction: column;
    }

    table {
        font-size: 0.8rem;
    }

    table th, table td {
        padding: 10px 12px;
    }

    .tabs {
        gap: 0;
    }

    .tab {
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    .modal {
        padding: 24px;
        margin: 12px;
    }
}

/* ── Utility ───────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }
.text-primary-color { color: var(--primary); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.hidden { display: none; }
