/* ============================================================
   Portfolio Management System — Admin UI
   Inspired by WordPress / Webflow / SaaS dashboards
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --accent: #f97316;
    --accent-dark: #ea580c;
    --accent-light: #ffedd5;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e5e7eb;
    --border-dark: #d1d5db;
    --text: #111827;
    --text-2: #4b5563;
    --text-3: #9ca3af;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --sidebar-bg: #111827;
    --sidebar-text: #d1d5db;
    --sidebar-active: rgba(37, 99, 235, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 260px;
    --topbar-h: 64px;
    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

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

/* ========== Layout ========== */
.admin-body { min-height: 100vh; }
.admin-layout { display: flex; min-height: 100vh; }
.main-wrapper { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

/* ========== Sidebar ========== */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    overflow-y: auto;
    z-index: 100;
    transition: transform var(--transition);
}
.sidebar-header {
    height: var(--topbar-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    color: #fff; font-weight: 700; font-size: 16px; text-decoration: none;
}
.logo-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
}
.sidebar-toggle { display: none; background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; }

.sidebar-nav { padding: 16px 12px; }
.nav-section { margin-bottom: 20px; }
.nav-label {
    display: block; padding: 8px 12px;
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    color: #6b7280; font-weight: 600;
}
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
    margin-bottom: 2px;
}
.nav-link i { width: 18px; text-align: center; opacity: 0.85; }
.nav-link:hover { background: rgba(255, 255, 255, 0.05); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link.active i { color: var(--primary); opacity: 1; }

/* ========== Topbar ========== */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 24px; gap: 16px;
    position: sticky; top: 0; z-index: 50;
}
.topbar-menu-btn {
    display: none;
    background: none; border: 0; font-size: 20px;
    color: var(--text-2); cursor: pointer; padding: 8px;
}
.topbar-title { margin: 0; font-size: 18px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* ========== User Menu ========== */
.dropdown { position: relative; }
.user-menu-btn {
    display: flex; align-items: center; gap: 10px;
    background: none; border: 0; cursor: pointer; padding: 6px 10px;
    border-radius: var(--radius); color: var(--text); transition: background var(--transition);
}
.user-menu-btn:hover { background: var(--surface-2); }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; font-weight: 600; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
}
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); min-width: 200px;
    box-shadow: var(--shadow-md); padding: 6px;
    display: none; z-index: 100;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: 4px;
    color: var(--text); font-size: 13px;
    transition: background var(--transition); text-decoration: none;
}
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }
.text-danger { color: var(--danger) !important; }

/* ========== Main Content ========== */
.main-content {
    flex: 1; padding: 24px;
    min-height: calc(100vh - var(--topbar-h) - 56px);
}
.admin-footer {
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 16px 24px;
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px; color: var(--text-3);
}
.footer-version { font-family: monospace; }

/* ========== Page Header ========== */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-title { margin: 0; font-size: 24px; font-weight: 700; }
.page-subtitle { color: var(--text-2); margin-top: 4px; font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ========== Stats Cards ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative; overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; margin-bottom: 14px;
}
.stat-card.primary .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card.accent .stat-icon { background: var(--accent-light); color: var(--accent); }
.stat-card.success .stat-icon { background: #d1fae5; color: var(--success); }
.stat-card.warning .stat-icon { background: #fef3c7; color: var(--warning); }
.stat-card .stat-label { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-card .stat-meta { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* ========== Cards ========== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
}
.card-title { margin: 0; font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ========== Buttons ========== */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13px; font-weight: 500;
    cursor: pointer; user-select: none;
    text-decoration: none;
    transition: all var(--transition);
    background: var(--surface); color: var(--text);
    border-color: var(--border);
    font-family: inherit;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-icon { padding: 8px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* ========== Forms ========== */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block; font-weight: 500; margin-bottom: 6px;
    font-size: 13px; color: var(--text);
}
.form-label .required { color: var(--danger); }
.form-help { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.form-control, .form-select, .form-textarea {
    display: block; width: 100%;
    padding: 9px 12px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { min-height: 120px; resize: vertical; }
.form-select { background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; appearance: none; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 768px) {
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* Checkboxes / Switches */
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border-dark); transition: var(--transition); border-radius: 24px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px;
    left: 3px; bottom: 3px; background: white;
    transition: var(--transition); border-radius: 50%;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ========== Tables ========== */
.table-wrapper { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; }
.table th {
    background: var(--surface-2);
    font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-2);
    border-bottom: 1px solid var(--border);
}
.table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child { border-bottom: 0; }
.table-actions { display: flex; gap: 4px; }

/* ========== Badges ========== */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; font-size: 11px; font-weight: 600;
    border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-accent { background: var(--accent-light); color: var(--accent-dark); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-secondary { background: var(--surface-2); color: var(--text-2); }

/* ========== Alerts ========== */
.alert {
    padding: 12px 16px; border-radius: var(--radius);
    margin-bottom: 16px; display: flex; align-items: center; gap: 10px;
    border: 1px solid; position: relative; font-size: 13px;
}
.alert-success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border-color: #bfdbfe; }
.alert-close {
    margin-left: auto; background: none; border: 0;
    font-size: 20px; cursor: pointer; color: inherit; opacity: 0.6;
}
.alert-close:hover { opacity: 1; }

/* ========== Modal ========== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
    z-index: 200; display: none;
}
.modal-overlay.show { display: block; }
.modal {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    background: var(--surface); border-radius: var(--radius-lg);
    width: 90%; max-width: 480px;
    z-index: 201; display: none;
    box-shadow: var(--shadow-lg);
}
.modal.show { display: block; transform: translate(-50%, -50%) scale(1); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { margin: 0; font-size: 16px; }
.modal-close { background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--text-3); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ========== Login Page ========== */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #f97316 100%);
    padding: 20px;
}
.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%; max-width: 420px;
}
.login-logo {
    text-align: center; margin-bottom: 28px;
}
.login-logo .logo-icon {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: 26px;
    margin-bottom: 12px;
}
.login-logo h1 { margin: 0; font-size: 22px; }
.login-logo p { color: var(--text-2); margin: 4px 0 0; font-size: 13px; }
.login-form .btn { margin-top: 8px; }
.login-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--text-3); }

/* ========== Image Uploader ========== */
.image-uploader {
    border: 2px dashed var(--border-dark);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--surface-2);
}
.image-uploader:hover, .image-uploader.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.image-uploader i { font-size: 36px; color: var(--primary); margin-bottom: 12px; }
.image-uploader p { margin: 0; color: var(--text-2); }
.image-uploader .upload-hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }

.image-preview {
    margin-top: 16px;
    position: relative;
    display: inline-block;
    max-width: 100%;
}
.image-preview img {
    max-width: 100%; max-height: 300px;
    border-radius: var(--radius); border: 1px solid var(--border);
}
.image-preview-actions {
    margin-top: 10px;
    display: flex; gap: 8px;
}

/* ========== Media Library ========== */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}
.media-item {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
    position: relative;
}
.media-item:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.media-thumb {
    aspect-ratio: 4/3; overflow: hidden; background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
}
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-info { padding: 8px 10px; font-size: 11px; }
.media-info .media-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-info .media-meta { color: var(--text-3); margin-top: 2px; }
.media-item .media-actions {
    position: absolute; top: 6px; right: 6px;
    display: flex; gap: 4px;
    opacity: 0; transition: opacity var(--transition);
}
.media-item:hover .media-actions { opacity: 1; }
.media-actions .btn { background: rgba(255, 255, 255, 0.95); padding: 4px 8px; font-size: 11px; }

/* ========== Portfolio Grid (admin) ========== */
.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.portfolio-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}
.portfolio-card:hover { box-shadow: var(--shadow-md); }
.portfolio-thumb {
    aspect-ratio: 16/10;
    overflow: hidden;
    background: var(--surface-2);
    position: relative;
}
.portfolio-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.portfolio-thumb .portfolio-badges {
    position: absolute; top: 10px; left: 10px;
    display: flex; gap: 4px; flex-wrap: wrap;
}
.portfolio-info { padding: 14px; }
.portfolio-info h4 { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.portfolio-info .portfolio-meta { font-size: 12px; color: var(--text-2); display: flex; gap: 10px; }
.portfolio-actions { padding: 10px 14px; border-top: 1px solid var(--border); display: flex; gap: 6px; background: var(--surface-2); }

/* ========== Empty State ========== */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: var(--text-2);
}
.empty-state i { font-size: 48px; color: var(--text-3); margin-bottom: 16px; }
.empty-state h3 { margin: 0 0 8px; color: var(--text); font-size: 18px; }
.empty-state p { margin: 0 0 20px; }

/* ========== Search Bar ========== */
.search-bar {
    display: flex; gap: 8px; align-items: center;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 0 12px;
    flex: 1; max-width: 400px;
}
.search-bar i { color: var(--text-3); }
.search-bar input {
    flex: 1; border: 0; padding: 9px 8px;
    background: transparent; outline: none; font-size: 13px;
}

/* ========== Filters ========== */
.filters {
    display: flex; gap: 8px; flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}
.filters .form-select, .filters .form-control { width: auto; min-width: 160px; padding: 7px 30px 7px 12px; font-size: 13px; }

/* ========== Bulk Actions ========== */
.bulk-actions {
    display: flex; gap: 8px; align-items: center;
    padding: 10px 16px;
    background: var(--primary-light); color: var(--primary-dark);
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.bulk-actions select { margin-left: auto; }

/* ========== API Key Cards ========== */
.api-key-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 10px;
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px;
}
.api-key-display {
    font-family: monospace;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: all;
}

/* ========== Responsive ========== */
@media (max-width: 1024px) {
    .main-wrapper { margin-left: 0; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .sidebar-toggle, .topbar-menu-btn { display: block; }
    .main-content { padding: 16px; }
    .page-title { font-size: 20px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
@media (max-width: 640px) {
    .topbar-title { font-size: 15px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 22px; }
    .portfolio-grid { grid-template-columns: 1fr; }
    .media-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

.d-none-md { display: inline-block; }
@media (max-width: 640px) { .d-none-md { display: none !important; } }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-3); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
