/* ============================================
   RedPrice - Main Stylesheet
   ============================================ */

:root {
    --color-primary: #c0392b;
    --color-primary-dark: #a93226;
    --color-primary-light: #e74c3c;
    --color-success: #27ae60;
    --color-warning: #f39c12;
    --color-danger: #e74c3c;
    --color-info: #3498db;

    --color-bg: #f5f6fa;
    --color-surface: #ffffff;
    --color-border: #e1e5eb;
    --color-border-light: #f0f1f4;

    --color-text: #2c3e50;
    --color-text-secondary: #7f8c8d;
    --color-text-muted: #bdc3c7;
    --color-text-inverse: #ffffff;

    --sidebar-width: 250px;
    --sidebar-bg: #1a1e2e;
    --sidebar-text: #a0aec0;
    --sidebar-text-active: #ffffff;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.2s ease;
}

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

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* --- Screens --- */
.screen { display: none; }
.screen.active { display: flex; }

/* --- Login --- */
#login-screen {
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1e2e 0%, #2c3e50 100%);
}
.login-container { width: 100%; max-width: 400px; padding: 2rem; }
.login-brand { text-align: center; margin-bottom: 2.5rem; }
.login-brand h1 { font-size: 2.5rem; font-weight: 700; color: #fff; letter-spacing: -0.5px; }
.login-brand h1 span { color: var(--color-primary-light); }
.login-brand p { color: var(--sidebar-text); margin-top: 0.5rem; }
.login-form {
    background: var(--color-surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* --- Forms --- */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.4rem; font-size: 0.9rem; }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.95rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(192,57,43,0.1);
}
.form-group input::placeholder { color: var(--color-text-muted); }
.form-group textarea { resize: vertical; min-height: 80px; }

.form-error {
    background: #fef2f2;
    color: var(--color-danger);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
}

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

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.form-group-inline input { width: 100px; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover:not(:disabled) { background: var(--color-border-light); }
.btn-danger { background: var(--color-danger); color: var(--color-text-inverse); }
.btn-text { background: none; border: none; color: var(--color-text-secondary); padding: 0.4rem; }
.btn-text:hover { color: var(--color-text); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 0.5rem; }

/* --- Sidebar --- */
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-width); height: 100vh;
    background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    z-index: 100; overflow-y: auto;
}
.sidebar-brand { padding: 1.5rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar-brand h2 { font-size: 1.4rem; font-weight: 700; color: #fff; }
.sidebar-brand h2 span { color: var(--color-primary-light); }

.sidebar-nav { list-style: none; padding: 0.75rem 0; flex: 1; }
.sidebar-nav li.admin-only { display: none; }
body.is-admin .sidebar-nav li.admin-only { display: block; }

.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 1.25rem;
    color: var(--sidebar-text); font-size: 0.9rem;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: var(--sidebar-text-active); }
.nav-link.active {
    background: rgba(192,57,43,0.3); color: var(--sidebar-text-active);
    border-left-color: var(--color-primary); font-weight: 500;
}
.nav-link svg { flex-shrink: 0; opacity: 0.7; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
    padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; justify-content: space-between;
}
.user-info { display: flex; flex-direction: column; }
.user-info span { color: var(--sidebar-text-active); font-size: 0.85rem; font-weight: 500; }
.user-info small { color: var(--sidebar-text); font-size: 0.75rem; text-transform: capitalize; }
.sidebar-footer .btn-text { color: var(--sidebar-text); }
.sidebar-footer .btn-text:hover { color: var(--color-primary-light); }

/* --- Main Content --- */
.main-content { margin-left: var(--sidebar-width); padding: 2rem; min-height: 100vh; }

/* --- Views --- */
.view { display: none; }
.view.active { display: block; }

.view-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem; padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border-light);
}
.view-header h1 { font-size: 1.5rem; font-weight: 600; }
.view-header-actions { display: flex; gap: 0.5rem; }

/* --- Filters bar --- */
.materials-filters {
    display: flex; gap: 1rem; margin-bottom: 1rem;
    align-items: center;
}
.materials-filters .form-group { margin-bottom: 0; }
.materials-filters select { min-width: 220px; }
.materials-filters input[type="text"] { min-width: 250px; }

/* --- Tables --- */
.table-container {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--color-bg); }
.data-table th {
    padding: 0.75rem 1rem; text-align: left;
    font-weight: 600; font-size: 0.8rem;
    color: var(--color-text-secondary);
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--color-border);
}
.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 0.9rem;
}
.data-table tbody tr:hover { background: #f8f9fb; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Number columns right-aligned */
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Badges --- */
.badge {
    display: inline-block; padding: 0.2rem 0.6rem;
    border-radius: 50px; font-size: 0.75rem; font-weight: 500;
}
.badge-success { background: #d4edda; color: #155724; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-warning { background: #fff3cd; color: #856404; }

/* --- 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; backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto;
}
.modal.modal-wide { max-width: 800px; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--color-border-light);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.5rem; color: var(--color-text-secondary); cursor: pointer; }
.modal-close:hover { color: var(--color-text); }
.modal-body { padding: 1.5rem; }
.modal-footer {
    padding: 1rem 1.5rem; border-top: 1px solid var(--color-border-light);
    display: flex; justify-content: flex-end; gap: 0.5rem;
}

/* --- Toast --- */
.toast-container {
    position: fixed; top: 1rem; right: 1rem; z-index: 2000;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
    background: var(--color-surface); border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); padding: 0.8rem 1.2rem;
    font-size: 0.9rem; min-width: 280px; max-width: 420px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--color-info);
}
.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-error { border-left-color: var(--color-danger); }
.toast.toast-warning { border-left-color: var(--color-warning); }

@keyframes slideIn { from { opacity:0; transform:translateX(50px); } to { opacity:1; transform:translateX(0); } }
@keyframes slideOut { from { opacity:1; transform:translateX(0); } to { opacity:0; transform:translateX(50px); } }

/* --- Utility --- */
.hidden { display: none !important; }
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }

.dashboard-welcome {
    background: var(--color-surface); border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm); padding: 2rem;
}
.dashboard-welcome p { font-size: 1rem; color: var(--color-text-secondary); }

/* --- Table group headers --- */
.table-group-header td {
    background: var(--color-bg);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

/* --- Inline editable markup --- */
.markup-input {
    width: 70px; padding: 0.3rem 0.5rem; text-align: right;
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-family: var(--font-family); font-size: 0.85rem;
}
.markup-input:focus { border-color: var(--color-primary); outline: none; }

/* --- Estimate Editor --- */
.editor-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem; padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border-light);
}
.editor-toolbar-left {
    display: flex; align-items: center; gap: 0.75rem;
}
.editor-toolbar-left h2 { font-size: 1.3rem; font-weight: 600; margin: 0; }
.editor-toolbar-right { display: flex; gap: 0.5rem; }

.editor-versions-bar {
    display: flex; align-items: center; gap: 0.25rem;
    margin-bottom: 1rem; flex-wrap: wrap;
}

.editor-actions-bar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.75rem;
}
.editor-markup-inline {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.9rem;
}
.editor-markup-inline label { font-weight: 500; white-space: nowrap; }

.editor-table .line-input {
    width: 100%; padding: 0.3rem 0.5rem;
    border: 1px solid var(--color-border-light); border-radius: var(--radius-sm);
    font-family: var(--font-family); font-size: 0.85rem;
    background: transparent;
}
.editor-table .line-input:focus {
    border-color: var(--color-primary); outline: none;
    background: var(--color-surface);
}
.editor-table .line-name { min-width: 180px; }
.editor-table .line-qty { width: 80px; text-align: right; }
.editor-table .line-price { width: 90px; text-align: right; }
.editor-table .line-unit { width: 55px; }

.editor-table tr.line-fixed { background: #f8f9fb; }
.editor-table tr.line-fixed td { color: var(--color-text-secondary); }

.editor-totals {
    background: var(--color-surface); border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm); padding: 1rem 1.5rem;
    margin-top: 1rem; max-width: 400px; margin-left: auto;
}
.editor-totals-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.4rem 0; font-size: 0.9rem;
}
.editor-totals-row + .editor-totals-row { border-top: 1px solid var(--color-border-light); }
.editor-grand-total {
    font-size: 1.1rem; padding-top: 0.6rem;
    border-top: 2px solid var(--color-primary) !important;
}
.editor-grand-total strong { color: var(--color-primary); }

.estimate-link { color: var(--color-primary); font-weight: 500; }
.estimate-link:hover { text-decoration: underline; }

/* --- Editor Actions Bar --- */
.editor-actions-left { display: flex; gap: 0.5rem; align-items: center; }

/* --- Editor Markup Row (in totals) --- */
.editor-markup-row .editor-markup-inline {
    display: flex; align-items: center; gap: 0.5rem;
}
.editor-markup-row .markup-input {
    width: 80px; padding: 0.3rem 0.5rem; text-align: right;
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-family: var(--font-family); font-size: 0.85rem;
}
.editor-markup-row .markup-input:focus {
    border-color: var(--color-primary); outline: none;
    box-shadow: 0 0 0 3px rgba(192,57,43,0.1);
}

/* --- Table Group Separator (Transport) --- */
.table-group-separator td {
    background: transparent !important;
    padding: 0.3rem 0 !important;
    border-bottom: 2px dashed var(--color-border) !important;
}

/* --- Files Panel --- */
.editor-files-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    overflow: hidden;
}
.editor-files-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border-light);
}
.editor-files-header strong { font-size: 0.85rem; }

.editor-dropzone {
    margin: 0.75rem 1rem;
    padding: 1.5rem;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    transition: all var(--transition);
}
.editor-dropzone.dragover {
    border-color: var(--color-primary);
    background: rgba(192,57,43,0.04);
    color: var(--color-primary);
}

.editor-files-list {
    padding: 0 1rem 0.75rem;
}

/* --- File Items --- */
.file-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border-light);
}
.file-item:last-child { border-bottom: none; }

.file-info {
    display: flex; align-items: center; gap: 0.75rem;
    min-width: 0; flex: 1;
}
.file-thumb {
    width: 40px; height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-light);
    cursor: pointer;
    transition: opacity var(--transition);
}
.file-thumb:hover { opacity: 0.8; }

.file-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    display: block;
}
.file-name:hover { text-decoration: underline; }

.file-actions {
    display: flex; align-items: center; gap: 0.25rem;
    flex-shrink: 0;
}

/* --- File Preview Overlay (Draggable) --- */
.file-preview-overlay {
    position: fixed; inset: 0;
    z-index: 1100;
    pointer-events: none;
}
.file-preview-window {
    position: fixed;
    top: 10%; left: 50%;
    transform: translateX(-50%);
    width: 70vw; max-width: 900px;
    height: 75vh;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    display: flex; flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
    z-index: 1101;
}
.file-preview-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--sidebar-bg);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: move;
    user-select: none;
}
.file-preview-header .modal-close {
    color: #fff;
    font-size: 1.3rem;
    opacity: 0.7;
}
.file-preview-header .modal-close:hover { opacity: 1; }

.file-preview-body {
    flex: 1; overflow: auto;
    display: flex; align-items: center; justify-content: center;
    padding: 0.5rem;
    background: #f0f0f0;
}
.file-preview-body img {
    max-width: 100%; max-height: 100%;
    object-fit: contain;
}
.file-preview-body iframe {
    width: 100%; height: 100%; border: none;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .materials-filters { flex-direction: column; }
    .editor-actions-left { flex-wrap: wrap; }
    .file-preview-window { width: 95vw; height: 60vh; }
    .editor-totals { max-width: 100%; }
}
