/**
 * Textile CMS - Admin Stylesheet
 */

/* ===========================================
   CSS Variables
   =========================================== */
:root {
    --primary: #C4724E;
    --primary-dark: #a85f3d;
    --secondary: #B8943E;
    --charcoal: #1a1a1a;
    --dark: #2c2420;
    --gray-900: #1f2937;
    --gray-800: #374151;
    --gray-700: #4b5563;
    --gray-600: #6b7280;
    --gray-500: #9ca3af;
    --gray-400: #B5AFA6;
    --gray-300: #E8DFD0;
    --gray-200: #f3f4f6;
    --gray-100: #f9fafb;
    --white: #ffffff;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    --sidebar-width: 260px;
    --topbar-height: 60px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --border-radius: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
}

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--gray-800);
    background-color: var(--gray-100);
}

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

button {
    font-family: inherit;
    cursor: pointer;
}

img {
    max-width: 100%;
    height: auto;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--charcoal);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo {
    color: var(--white);
    font-size: 1.125rem;
    font-weight: 600;
}

.sidebar-logo span {
    display: block;
    font-size: 0.7rem;
    color: var(--gray-500);
    font-weight: 400;
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    padding: 0.5rem 1.5rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.625rem 1.5rem;
    color: var(--gray-400);
    font-size: 0.8rem;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.nav-item:hover {
    color: var(--white);
    background: rgba(255,255,255,0.05);
}

.nav-item.active {
    color: var(--white);
    background: rgba(255,255,255,0.1);
    border-left-color: var(--primary);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    margin-right: 0.75rem;
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

.nav-badge {
    margin-left: auto;
    background: var(--primary);
    color: var(--white);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.admin-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.admin-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 0.8rem;
    font-weight: 600;
}

.admin-name {
    color: var(--white);
    font-size: 0.8rem;
    font-weight: 500;
}

.admin-role {
    color: var(--gray-500);
    font-size: 0.7rem;
}

.logout-btn {
    width: 100%;
    padding: 0.5rem;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: var(--border-radius);
    color: var(--gray-400);
    font-size: 0.75rem;
    transition: all var(--transition);
}

.logout-btn:hover {
    background: rgba(255,255,255,0.15);
    color: var(--white);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Top Bar */
.topbar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-300);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--charcoal);
}

.topbar-breadcrumb {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-left: 0.5rem;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border: none;
    border-radius: var(--border-radius);
    color: var(--gray-600);
    position: relative;
    transition: all var(--transition);
}

.topbar-btn:hover {
    background: var(--gray-200);
    color: var(--charcoal);
}

.topbar-btn .badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--error);
    color: var(--white);
    font-size: 0.6rem;
    font-weight: 600;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Content Area */
.content {
    flex: 1;
    padding: 1.5rem;
}

/* ===========================================
   Components
   =========================================== */

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--charcoal);
}

.card-body {
    padding: 1.25rem;
}

/* Stat Cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    border: 1px solid var(--gray-200);
}

.stat-card-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--charcoal);
}

.stat-card-icon {
    float: right;
    width: 40px;
    height: 40px;
    background: var(--gray-100);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    transition: all var(--transition);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

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

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

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

.btn-secondary:hover {
    background: var(--gray-200);
}

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

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.375rem;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    color: var(--charcoal);
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(196, 114, 78, 0.1);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-error {
    color: var(--error);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-100);
}

.table td {
    font-size: 0.85rem;
}

.table tr:hover {
    background: var(--gray-100);
}

/* Status Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 4px;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-error {
    background: #fee2e2;
    color: #991b1b;
}

.badge-gray {
    background: var(--gray-200);
    color: var(--gray-600);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.875rem 1.25rem;
    background: var(--charcoal);
    color: var(--white);
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--error); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info { border-left: 3px solid var(--info); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--white);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--gray-500);
    font-size: 1.25rem;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--charcoal);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(90vh - 140px);
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* Image Upload */
.image-upload {
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}

.image-upload:hover {
    border-color: var(--primary);
    background: rgba(196, 114, 78, 0.05);
}

.image-upload.dragover {
    border-color: var(--primary);
    background: rgba(196, 114, 78, 0.1);
}

.image-upload input {
    display: none;
}

.image-preview {
    width: 100%;
    max-width: 200px;
    margin: 1rem auto 0;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.image-preview img {
    width: 100%;
    height: auto;
}

/* ===========================================
   Responsive
   =========================================== */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: flex !important;
    }
}

.mobile-menu-btn {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    margin-right: 1rem;
}

@media (max-width: 768px) {
    .stat-cards {
        grid-template-columns: 1fr 1fr;
    }

    .content {
        padding: 1rem;
    }

    .table th,
    .table td {
        padding: 0.5rem 0.75rem;
    }
}

@media (max-width: 480px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }
}

/* ===========================================
   Drag & Drop Reorder
   =========================================== */
.table tbody tr[draggable="true"] {
    cursor: grab;
    transition: opacity 0.15s, background-color 0.15s;
}

.table tbody tr[draggable="true"]:active {
    cursor: grabbing;
}

.table tbody tr.drag-over {
    background-color: #fef3c7;
    box-shadow: inset 0 -2px 0 0 var(--primary);
}

/* Ensure buttons inside draggable rows work properly */
.table tbody tr[draggable="true"] .btn {
    position: relative;
    z-index: 1;
    user-select: none;
}
