/* Outrank Content Engine -- Dark Theme */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242736;
    --bg-hover: #2d3044;
    --border: #2d3044;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { overflow-x: hidden; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    max-width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-logo {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.sidebar-logo .site-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.sidebar nav {
    flex: 1;
    padding: 12px 0;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
}

.sidebar nav a:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar nav a.active { background: var(--bg-tertiary); color: var(--accent); border-right: 2px solid var(--accent); }

.sidebar nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.site-switcher {
    margin-top: 8px;
}

.site-switcher select {
    width: 100%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 13px;
}

/* Main Content */
.main {
    margin-left: var(--sidebar-width);
    padding: 24px 32px;
    min-height: 100vh;
    width: calc(100vw - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
}

.stat-card .label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card .sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Cards / Panels */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

td { color: var(--text-secondary); }

tr:hover td { background: var(--bg-hover); }

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-draft { background: rgba(99, 102, 241, 0.15); color: var(--accent); }
.badge-published { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-failed { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-generating { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge-generated { background: rgba(99, 102, 241, 0.15); color: var(--accent); }
.badge-scheduled { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge-planned { background: rgba(113, 113, 122, 0.15); color: var(--text-muted); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.btn-success:hover { background: rgba(34, 197, 94, 0.25); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input[type="text"], input[type="password"], input[type="number"],
input[type="url"], input[type="email"], input[type="time"],
select, textarea {
    width: 100%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea { min-height: 120px; resize: vertical; }

/* Calendar */
.calendar-month-section { margin-bottom: 40px; }
.calendar-month-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--border);
    border-radius: 10px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
}

.calendar-header {
    background: var(--bg-tertiary);
    padding: 10px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.calendar-day {
    background: var(--bg-secondary);
    min-height: 100px;
    min-width: 0;
    max-width: 100%;
    padding: 8px;
    position: relative;
    overflow: hidden;
}

.calendar-day.other-month { background: var(--bg-primary); opacity: 0.5; }
.calendar-day.today { border: 2px solid var(--accent); }

.calendar-day .day-number {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.calendar-event {
    display: block;
    padding: 3px 6px;
    margin-bottom: 2px;
    border-radius: 4px;
    font-size: 11px;
    color: #fff;
    text-decoration: none;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}

.calendar-event:hover { opacity: 0.8; }

.calendar-event-published {
    display: block;
    padding: 3px 6px;
    margin-bottom: 2px;
    border-radius: 4px;
    font-size: 11px;
    color: #fff;
    text-decoration: none;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    min-width: 0;
    background: var(--success);
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.4);
}

.calendar-event-published:hover { opacity: 0.8; }

.calendar-event-planned {
    display: block;
    padding: 3px 6px;
    margin-bottom: 2px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    min-width: 0;
    cursor: pointer;
}

.calendar-event-planned:hover { background: var(--bg-hover); }

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.calendar-nav h2 {
    font-size: 20px;
    font-weight: 600;
    min-width: 200px;
}

/* Pillar indicators */
.pillar-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.pillar-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

/* Progress bar */
.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar .fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

/* Article preview */
.article-preview {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 32px;
    border-radius: 10px;
    max-width: 800px;
    line-height: 1.7;
    font-size: 16px;
    border: 1px solid var(--border);
}

.article-preview h2 { font-size: 24px; margin: 28px 0 12px; color: var(--text-primary); }
.article-preview h3 { font-size: 20px; margin: 20px 0 8px; color: var(--text-secondary); }
.article-preview p { margin-bottom: 16px; color: var(--text-secondary); }
.article-preview ul, .article-preview ol { margin: 0 0 16px 24px; color: var(--text-secondary); }
.article-preview li { margin-bottom: 6px; }
.article-preview a { color: var(--accent-hover); }
.article-preview strong { font-weight: 600; color: var(--text-primary); }
.article-preview table { border: 1px solid var(--border); }
.article-preview th { background: var(--bg-hover); }
.article-preview td, .article-preview th { border: 1px solid var(--border); padding: 8px 12px; }
.article-preview img { border-radius: 8px; max-width: 100%; height: auto; }

/* Editor layout */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
}

.editor-sidebar .meta-item {
    margin-bottom: 12px;
}

.editor-sidebar .meta-item .meta-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.editor-sidebar .meta-item .meta-value {
    font-size: 14px;
    color: var(--text-primary);
    margin-top: 2px;
}

/* Keyword list in pillars page */
.keyword-list {
    list-style: none;
}

.keyword-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.keyword-item:last-child { border-bottom: none; }

.keyword-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.keyword-type {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    color: #fff;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--error); }

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
}

.login-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 360px;
}

.login-box h1 {
    font-size: 24px;
    margin-bottom: 24px;
    text-align: center;
}

.login-box .error {
    color: var(--error);
    font-size: 13px;
    margin-bottom: 12px;
    text-align: center;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 500;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
}

.modal h3 { margin-bottom: 12px; }
.modal p { color: var(--text-secondary); margin-bottom: 16px; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; padding: 16px; }
    .editor-layout { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Filters bar */
.filters-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters-bar input, .filters-bar select {
    width: auto;
    min-width: 160px;
}

/* Pillar accordion */
.pillar-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    overflow: hidden;
}

.pillar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
    transition: background 0.15s;
}

.pillar-header:hover { background: var(--bg-hover); }

.pillar-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pillar-header h3 { font-size: 15px; font-weight: 600; }

.pillar-body {
    padding: 0 20px 16px;
    display: none;
}

.pillar-body.open { display: block; }

.pillar-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 20px;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-btn .spinner { margin-right: 6px; }
.loading-btn { pointer-events: none; opacity: 0.7; }

/* Disabled form states */
input:disabled, select:disabled, textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Back link in editor */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 8px;
}
.back-link:hover { color: var(--accent); }

/* Sidebar article count badge */
.nav-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 8px;
    margin-left: auto;
}

/* Responsive filters */
@media (max-width: 640px) {
    .filters-bar { flex-direction: column; }
    .filters-bar input, .filters-bar select { width: 100%; min-width: unset; }
}
