/* Import Inter - the cleanest UI font used by top-tier tech brands */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary-red: #e11d48; /* High-vibrancy Crimson */
    --primary-red-glow: rgba(225, 29, 72, 0.15);
    --dark-bg: #09090b;     /* Rich Obsidian */
    --sidebar-bg: #0d0d0e;  /* Darker sidebar */
    --card-bg: #141414;     /* Deep Charcoal */
    --glass-bg: rgba(20, 20, 20, 0.8);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --text-main: #f4f4f5;
    --text-dim: #a1a1aa;
    --radius: 12px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--dark-bg);
    color: var(--text-main);
    line-height: 1.5;
    display: flex;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ================== THE SIDEBAR (PHASE 3 REDESIGN) ================== */
.sidebar {
    width: 260px;
    min-width: 260px;
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 28px 16px;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow-y: auto;
}

.sidebar-header {
    text-align: center;
    margin-bottom: 8px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header img {
    width: 100px;
    max-width: 100%;
    height: auto;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 10px rgba(225, 29, 72, 0.35));
}

.sidebar-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-main);
}

.sidebar-header h2::before {
    display: none;
}

.user-box {
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border);
    padding: 14px 12px;
    border-radius: var(--radius);
    text-align: center;
    margin: 16px 0 20px 0;
}

.user-box .user-role {
    font-size: 10px;
    color: var(--primary-red);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
}

.user-box .user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    margin-top: 4px;
}

/* Nav Section Label */
.nav-section-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    padding: 20px 12px 8px 12px;
    font-weight: 600;
}

/* Sidebar Nav Links (Icon + Text) */
.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-dim);
    text-decoration: none;
    padding: 11px 14px;
    border-radius: 8px;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 13.5px;
    transition: var(--transition-smooth);
    border: 1px solid transparent;
}

.sidebar .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 15px;
    opacity: 0.7;
    transition: var(--transition-smooth);
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    border-color: var(--border);
}

.sidebar .nav-link:hover i {
    opacity: 1;
    color: var(--primary-red);
}

.sidebar .nav-link.active {
    background: var(--primary-red-glow);
    color: var(--primary-red);
    border-color: rgba(225, 29, 72, 0.2);
    font-weight: 600;
}

.sidebar .nav-link.active i {
    opacity: 1;
    color: var(--primary-red);
}

/* Sidebar Logout Link */
.sidebar .nav-link.nav-logout {
    margin-top: auto;
    color: var(--primary-red);
    border: 1px solid rgba(225, 29, 72, 0.25);
    background: rgba(225, 29, 72, 0.04);
    justify-content: center;
}

.sidebar .nav-link.nav-logout:hover {
    background: rgba(225, 29, 72, 0.12);
    border-color: var(--primary-red);
}

/* Legacy sidebar link fallback */
.sidebar a:not(.nav-link) {
    color: var(--text-dim);
    text-decoration: none;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.sidebar a:not(.nav-link):hover, .sidebar a:not(.nav-link).active {
    background: rgba(225, 29, 72, 0.1);
    color: var(--primary-red);
}

/* ================== MAIN CONTENT AREA ================== */
.main-content {
    flex: 1;
    padding: 36px 40px;
    max-width: 1280px;
    margin-left: 260px;
    width: calc(100% - 260px);
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.page-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.page-header .header-badge {
    font-size: 11px;
    color: var(--text-dim);
    background: rgba(255,255,255,0.04);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

/* ================== STATS GRID (4 CARDS) ================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card-bg);
    padding: 22px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    text-decoration: none;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: var(--transition-smooth);
    cursor: default;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-red), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.stat-card:hover::after {
    opacity: 1;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-icon.red { background: rgba(225, 29, 72, 0.12); color: var(--primary-red); }
.stat-icon.amber { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.stat-icon.blue { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.stat-icon.green { background: rgba(34, 197, 94, 0.12); color: #22c55e; }

.stat-info h4 {
    margin: 0 0 6px 0;
    color: var(--text-dim);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 500;
}

.stat-info .value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

/* ================== THE CARDS (GLASS LOOK) ================== */
.card, .form-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

.card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 2px;
    background: linear-gradient(90deg, var(--primary-red), transparent);
}

.card-title {
    margin: 0 0 18px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title i {
    color: var(--primary-red);
    font-size: 14px;
}

/* ================== ENHANCED SEARCH BAR ================== */
.search-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-input-wrap {
    flex: 1;
    position: relative;
}

.search-input-wrap i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 14px;
    pointer-events: none;
}

.search-input-wrap input {
    width: 100%;
    padding: 12px 15px 12px 40px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--dark-bg);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 13.5px;
    transition: var(--transition-smooth);
}

.search-input-wrap input:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.1);
}

/* Legacy search input */
.search-container input {
    flex: 1;
    padding: 12px 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--dark-bg);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
}
.search-container input:focus {
    outline: none;
    border-color: var(--primary-red);
}

/* ================== TABLES ================== */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #0c0c0c;
}

th {
    background: #151515;
    padding: 14px 16px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    font-weight: 600;
}

td {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    font-size: 13.5px;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.015);
}

/* Clickable PR Link */
.link-pr {
    color: var(--primary-red);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.link-pr:hover {
    color: #fb7185;
    text-decoration: underline;
}

/* PO Link */
.link-po {
    color: var(--primary-red);
    font-weight: 600;
    text-decoration: none;
}
.link-po:hover {
    text-decoration: underline;
}

/* Status Badges */
.badge {
    padding: 4px 12px;
    font-size: 11px;
    border-radius: 20px;
    font-weight: 600;
    display: inline-block;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.badge-pending { background: rgba(245, 158, 11, 0.1); color: #f59e0b; border-color: rgba(245, 158, 11, 0.2); }
.badge-approved { background: rgba(34, 197, 94, 0.1); color: #22c55e; border-color: rgba(34, 197, 94, 0.2); }
.badge-issued { background: rgba(59, 130, 246, 0.1); color: #3b82f6; border-color: rgba(59, 130, 246, 0.2); }

/* ================== DETAIL MODAL (VIEW-ONLY) ================== */
.modal-overlay {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow-y: auto;
    animation: modalFadeIn 0.25s ease;
}

.modal-overlay.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
}

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

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

.modal-card {
    background: var(--card-bg);
    width: 100%;
    max-width: 750px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    animation: modalSlideUp 0.3s ease;
    position: relative;
    overflow: hidden;
}

.modal-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-red), #fb7185, transparent);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text-main);
}

.modal-header h3 span {
    color: var(--primary-red);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.modal-close:hover {
    background: rgba(225, 29, 72, 0.12);
    color: var(--primary-red);
    border-color: rgba(225, 29, 72, 0.3);
}

.modal-body {
    padding: 24px 28px;
    max-height: 75vh;
    overflow-y: auto;
}

/* Modal Info Grid */
.modal-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    background: rgba(255,255,255,0.02);
    padding: 18px;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 22px;
}

.modal-info-grid .info-item label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 3px;
    font-weight: 600;
}

.modal-info-grid .info-item span {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    display: block;
}

/* Modal Section Titles */
.modal-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-red);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 22px 0 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Modal Signature Stamps */
.modal-signatures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-top: 12px;
}

.sig-stamp {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
}

.sig-stamp .sig-role {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    font-weight: 600;
    margin-bottom: 8px;
}

.sig-stamp .sig-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
}

.sig-stamp img {
    max-width: 140px;
    max-height: 70px;
    margin: 6px 0;
    border-radius: 4px;
    background: #fff;
    padding: 4px;
}

.sig-stamp .sig-date {
    font-size: 11px;
    color: var(--text-dim);
}

/* Modal Loading State */
.modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-dim);
    gap: 16px;
}

.modal-loading .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary-red);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ================== FORMS & INPUTS ================== */
.grid-2 { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); 
    gap: 20px; 
}

label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 8px;
    display: block;
}

input, textarea, select {
    width: 100%;
    background: #000;
    border: 1px solid var(--border);
    padding: 14px;
    border-radius: 8px;
    color: rgb(139, 132, 193);
    font-family: inherit;
    transition: border 0.3s;
}

input:focus {
    border-color: var(--primary-red);
    outline: none;
    box-shadow: 0 0 0 4px rgba(225, 29, 72, 0.1);
}

/* ================== PREMIUM BUTTONS ================== */
.btn-primary, .btn-submit, .btn-confirm {
    background: var(--primary-red);
    color: rgb(255, 255, 255);
    padding: 14px 28px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, background 0.3s;
    display: inline-block;
    text-align: center;
    text-decoration: none !important;
}

.btn-primary:hover {
    background: #fb7185;
    transform: translateY(-2px);
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-main);
    padding: 12px 22px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
    text-decoration: none;
    display: inline-block;
    text-align: center;
    font-size: 13px;
}

.btn-ghost:hover {
    border-color: var(--text-dim);
    background: rgba(255,255,255,0.04);
}

/* ================== MOBILE APP UI FIXES ================== */
@media (max-width: 900px) {
    body { flex-direction: column; }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        padding: 16px;
        position: relative;
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        justify-content: flex-start;
        gap: 8px;
    }

    .sidebar-header, .user-box, .nav-section-label { display: none; }

    .sidebar .nav-link {
        white-space: nowrap;
        margin-bottom: 0;
        padding: 8px 14px;
        font-size: 13px;
    }

    .sidebar .nav-link span { display: none; }
    .sidebar .nav-link i { margin: 0; font-size: 18px; }

    .main-content {
        padding: 20px 15px;
        width: 100%;
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card { padding: 16px; }
    .stat-info .value { font-size: 22px; }

    .card {
        padding: 20px;
    }

    .modal-overlay.active {
        padding: 20px 12px;
    }

    .modal-card {
        max-width: 100%;
    }

    .modal-info-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 500px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ================== SIGNATURE MODULE ================== */
.segment-control {
    display: flex;
    background: #000;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
}
.segment-label {
    flex: 1;
    text-align: center;
    padding: 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    transition: all 0.3s ease;
}
.segment-label input {
    display: none;
}
.segment-label.active {
    background: var(--primary-red);
    color: #fff;
}

.signature-container {
    background: #fff;
    border-radius: 8px;
    border: 2px solid var(--border);
    overflow: hidden;
    margin-bottom: 10px;
}

canvas {
    display: block;
    width: 100%;
    height: 200px;
}

/* Custom File Input Styling */
.custom-file-upload {
    display: inline-block;
    padding: 12px 20px;
    cursor: pointer;
    background: #18181b;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    text-align: center;
    width: 100%;
}
.custom-file-upload:hover {
    border-color: var(--primary-red);
    background: rgba(225, 29, 72, 0.05);
}
input[type="file"].hidden-file-input {
    display: none;
}

/* Secondary Button (Outline Red) */
.btn-secondary {
    background: transparent;
    color: var(--primary-red);
    padding: 10px 15px;
    border: 1px solid var(--primary-red);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: inline-block;
    text-align: center;
}
.btn-secondary:hover {
    background: rgba(225, 29, 72, 0.1);
}

.hidden {
    display: none;
}

/* Fix for centering the login page */
body.login-page {
    display: flex;
    flex-direction: column;
}

/* ================== EMPTY STATE ================== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dim);
}

.empty-state i {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 13px;
}

/* ================== TOAST NOTIFICATION SYSTEM ================== */
#toast-container {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #1c1c1e;
    color: var(--text-main);
    font-size: 13.5px;
    font-weight: 500;
    min-width: 280px;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    pointer-events: all;
    animation: toastSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.hiding {
    opacity: 0;
    transform: translateX(30px);
}

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.toast.toast-success { border-left: 3px solid #22c55e; }
.toast.toast-success .toast-icon { color: #22c55e; }
.toast.toast-error { border-left: 3px solid var(--primary-red); }
.toast.toast-error .toast-icon { color: var(--primary-red); }
.toast.toast-warning { border-left: 3px solid #f59e0b; }
.toast.toast-warning .toast-icon { color: #f59e0b; }
.toast.toast-info { border-left: 3px solid #3b82f6; }
.toast.toast-info .toast-icon { color: #3b82f6; }

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