/* ============================================
   TIMBER DESIGN SYSTEM — common.css
   Shared styles across all 11 pages.
   Default theme: admin blue (#667eea).
   Pages override :root for custom themes.
   ============================================ */

/* --- CSS Variables --- */
:root {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --primary-light: #e8ebff;
    --success: #28a745;
    --success-light: #d4edda;
    --error: #dc3545;
    --error-light: #f8d7da;
    --warning: #ffc107;
    --warning-light: #fff3cd;
    --info: #339af0;
    --info-light: #d1ecf1;
    --surface: #FFFFFF;
    --background: #f8f9ff;
    --on-surface: #333;
    --on-surface-variant: #666;
    --outline: #e0e7ff;
    --border-color: #e0e7ff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-display: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

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

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

.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover { background: #5a6268; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--outline);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm { padding: 8px 16px; font-size: 13px; }

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}

/* --- Forms / Inputs --- */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--on-surface);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--outline);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled {
    background: var(--background);
    cursor: not-allowed;
    opacity: 0.6;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 11px;
    font-weight: bold;
}

.badge-success { background: var(--success-light); color: #155724; }
.badge-danger { background: var(--error-light); color: #721c24; }
.badge-warning { background: var(--warning-light); color: #6d5302; }
.badge-info { background: var(--info-light); color: #0c5460; }

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

thead { background: var(--background); }

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--on-surface);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--background);
}

tr:hover { background: var(--background); }

.table-container { overflow: auto; max-height: 70vh; }

table tbody tr:nth-child(even) { background: #f9fafb; }

/* --- Messages / Alerts --- */
.message {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 14px;
    display: none;
}

.message.success {
    background: var(--success-light);
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background: var(--error-light);
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message.show {
    display: block;
    animation: slideDown 0.3s ease;
}

.alert {
    padding: 15px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-weight: 500;
}

.alert-success { background: var(--success-light); color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: var(--error-light); color: #721c24; border: 1px solid #f5c6cb; }
.alert-info { background: var(--info-light); color: #0c5460; border: 1px solid #bee5eb; }

/* --- Spinner / Loading --- */
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

.loading {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.empty-state-icon {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    color: var(--on-surface);
    margin-bottom: 10px;
}

.empty-state p {
    color: var(--on-surface-variant);
}

/* --- Progress Bar (indeterminate) --- */
.progress-bar { height: 4px; background: var(--outline); border-radius: 2px; overflow: hidden; display: none; }
.progress-bar.active { display: block; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 2px; animation: indeterminate 1.5s infinite; }

/* --- Field Validation --- */
.field-error { color: var(--error); font-size: 12px; margin-top: 4px; display: block; }
.input-error { border-color: var(--error) !important; }

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
}

.toast {
    background: #323232;
    color: white;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    margin-top: 8px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    font-size: 14px;
}

.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }

/* --- Confirm Modal --- */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.confirm-box {
    background: white;
    border-radius: var(--radius-lg);
    padding: 30px;
    max-width: 440px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
    animation: slideUp 0.2s ease;
}

.confirm-box h3 {
    margin-bottom: 10px;
    color: var(--on-surface);
    font-size: 18px;
}

.confirm-box p {
    color: var(--on-surface-variant);
    margin-bottom: 24px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-line;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 120px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Modals --- */
/* Overlay: supports both .modal-overlay and .modal class names */
.modal-overlay,
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active,
.modal.active,
.modal.show {
    display: flex;
}

/* Content box (used by .modal pattern as direct child) */
.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 30px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

/* Inner .modal inside .modal-overlay — reset overlay styles */
.modal-overlay > .modal {
    display: block;
    position: static;
    inset: auto;
    background: transparent;
    z-index: auto;
}

/* Inner box (used by .modal-overlay pattern: overlay > .modal-box) */
.modal-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

/* Header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2,
.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--on-surface);
    margin: 0;
}

/* Close button (X) */
.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--on-surface-variant);
    padding: 4px;
    border-radius: 50%;
    font-size: 1.2rem;
    display: flex;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(0,0,0,0.06);
    color: var(--on-surface);
}

/* Legacy close (admin.html pattern) */
.close {
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #000;
}

/* Body */
.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(90vh - 130px);
}

/* Footer / Actions */
.modal-footer,
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    /* Form rows stack vertically */
    .form-row { grid-template-columns: 1fr; }

    /* Tables: remove fixed height so page scrolls naturally */
    .table-container { max-height: none; }

    /* Modals: full-width on mobile */
    .modal-content,
    .modal-box {
        width: 95%;
        max-width: none;
        max-height: 85vh;
        margin: 20px;
    }

    /* Confirm dialog */
    .confirm-box { width: 95%; }

    /* Buttons wrap in modal/confirm actions */
    .modal-actions,
    .modal-footer,
    .confirm-actions { flex-wrap: wrap; }

    /* Toasts: full width at bottom */
    .toast-container { left: 10px; right: 10px; bottom: 10px; }
    .toast { max-width: none; }
}

/* --- Skip Link (Accessibility) --- */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
}

/* --- Required Field Indicators --- */
.form-group label .required,
.form-group label.required::after {
    content: ' *';
    color: #dc2626;
    font-weight: 700;
}

/* --- Animations --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

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

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes indeterminate {
    0% { width: 0%; margin-left: 0; }
    50% { width: 60%; margin-left: 20%; }
    100% { width: 0%; margin-left: 100%; }
}

/* Touch targets pe dispozitive cu deget (WCAG 2.5.8) */
@media (pointer: coarse) {
    .btn-sm, .btn-icon, .btn-icon-sm, .action-btn { min-height: 40px; min-width: 40px; }
    .pagination-controls button { min-height: 40px; min-width: 36px; }
}
