@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #1e3a5f;
    --primary-light: #2d5a8a;
    --accent: #0ea5e9;
    --accent-dark: #0284c7;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --surface: #ffffff;
    --bg: #eef2f7;
    --bg-auth: linear-gradient(135deg, #0f172a 0%, #1e3a5f 45%, #0c4a6e 100%);
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

body {
    font-family: 'Cairo', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

body.auth-page {
    background: var(--bg-auth);
    display: flex;
    flex-direction: column;
}

/* Navbar */
.app-navbar {
    background: linear-gradient(135deg, #0f172a 0%, var(--primary) 100%);
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    padding: .6rem 0;
}

.app-navbar .navbar-brand {
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -.02em;
}

.app-navbar .nav-link {
    font-weight: 500;
    padding: .45rem .85rem !important;
    border-radius: 8px;
    margin: 0 .1rem;
    transition: background .2s;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
    background: rgba(255,255,255,.12);
}

.app-navbar .user-chip {
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 999px;
    padding: .35rem .9rem;
    font-size: .85rem;
}

.notif-badge { font-size: .65rem; vertical-align: top; }

/* Page layout */
.page-header {
    margin-bottom: 1.75rem;
}

.page-header h1,
.page-header h2 {
    font-weight: 800;
    color: var(--primary);
    margin-bottom: .25rem;
}

.page-header .subtitle {
    color: var(--text-muted);
    font-size: .95rem;
}

/* Cards */
.app-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.app-card .card-header {
    background: linear-gradient(to left, #f8fafc, #fff);
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--primary);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.app-card .card-header i {
    color: var(--accent);
}

.app-card .card-body { padding: 1.25rem; }

.section-card {
    border-right: 4px solid var(--accent);
}

.section-card.warning-border { border-right-color: var(--warning); }
.section-card.success-border { border-right-color: var(--success); }

/* Stats */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.stat-box::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
}

.stat-box.warning::before { background: var(--warning); }
.stat-box.success::before { background: var(--success); }
.stat-box.primary::before { background: var(--primary); }
.stat-box.accent::before { background: var(--accent); }
.stat-box.accent { color: inherit; transition: transform .15s, box-shadow .15s; }
.stat-box.accent:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-box .stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-box .stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.2;
}

/* Forms */
.form-label {
    font-weight: 600;
    color: var(--text);
    font-size: .9rem;
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    padding: .6rem .85rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

.form-section-title {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 2px solid var(--border);
}

.form-section-num {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    font-weight: 800;
    flex-shrink: 0;
}

/* Items table (request form) */
.items-table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fafbfc;
}

.items-table {
    width: 100%;
    margin: 0;
}

.items-table thead th {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    padding: .75rem .65rem;
    border: none;
    white-space: nowrap;
}

.items-table tbody td {
    padding: .5rem .4rem;
    vertical-align: middle;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.items-table tbody tr:last-child td { border-bottom: none; }

.items-table .form-control {
    padding: .45rem .6rem;
    font-size: .9rem;
}

.items-table .line-total {
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    min-width: 90px;
}

.items-table .row-num {
    text-align: center;
    color: var(--text-muted);
    font-weight: 600;
    width: 40px;
}

.items-table tfoot td {
    background: #f1f5f9;
    font-weight: 700;
    padding: .85rem .65rem;
    border-top: 2px solid var(--border);
}

.grand-total-value {
    font-size: 1.25rem;
    color: var(--accent-dark);
}

.btn-add-row {
    border: 2px dashed var(--accent);
    color: var(--accent-dark);
    background: rgba(14, 165, 233, .06);
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: .55rem 1rem;
    transition: all .2s;
}

.btn-add-row:hover {
    background: rgba(14, 165, 233, .12);
    border-color: var(--accent-dark);
    color: var(--accent-dark);
}

.btn-remove-row {
    color: var(--danger);
    border: none;
    background: transparent;
    padding: .25rem .5rem;
    border-radius: 6px;
}

.btn-remove-row:hover { background: rgba(239, 68, 68, .1); }

/* Buttons */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: .55rem 1.1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-dark), #0369a1);
    box-shadow: 0 4px 14px rgba(14, 165, 233, .35);
}

.btn-accent {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: none;
    color: #fff;
}

.btn-accent:hover {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff;
}

/* Tables */
.app-table {
    margin: 0;
}

.app-table thead th {
    background: #f8fafc;
    font-weight: 700;
    font-size: .82rem;
    color: var(--text-muted);
    text-transform: none;
    border-bottom: 2px solid var(--border);
    padding: .85rem 1rem;
}

.app-table tbody td {
    padding: .85rem 1rem;
    vertical-align: middle;
    border-color: var(--border);
}

.app-table tbody tr:hover { background: #f8fafc; }

/* Badges */
.status-badge { font-size: .78rem; font-weight: 600; padding: .4em .75em; }

.badge-soft-primary {
    background: rgba(14, 165, 233, .12);
    color: var(--accent-dark);
}

/* Auth page */
.auth-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    background: var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-width: 440px;
    width: 100%;
}

.auth-card-header {
    background: linear-gradient(135deg, var(--primary), #0c4a6e);
    color: #fff;
    padding: 2rem 2rem 1.5rem;
    text-align: center;
}

.auth-card-header .logo-icon {
    width: 64px;
    height: 64px;
    background: rgba(255,255,255,.15);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.75rem;
}

.auth-card-header h1 {
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0;
}

.auth-card-body { padding: 2rem; }

.auth-hint {
    background: #f8fafc;
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    font-size: .82rem;
    color: var(--text-muted);
}

/* Detail table (request view items) */
.detail-items-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-items-table th,
.detail-items-table td {
    padding: .75rem 1rem;
    border: 1px solid var(--border);
}

.detail-items-table thead th {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.detail-items-table tfoot td {
    background: #f1f5f9;
    font-weight: 700;
}

.detail-items-table tbody tr:nth-child(even) { background: #fafbfc; }

/* Misc */
.file-info { font-size: .875rem; color: var(--text-muted); }

.signature-pad {
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: crosshair;
    touch-action: none;
}

.nav-tabs-sm .nav-link { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

.timeline-item {
    border-right: 3px solid var(--accent);
    padding-right: 1rem;
    margin-bottom: 1rem;
}

.main-file-banner {
    background: linear-gradient(to left, #eff6ff, #f0f9ff);
    border: 1px solid #bae6fd;
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.alert {
    border-radius: var(--radius-sm);
    border: none;
}

.alert-success { background: #ecfdf5; color: #065f46; }
.alert-danger { background: #fef2f2; color: #991b1b; }
.alert-info { background: #eff6ff; color: #1e40af; }
.alert-warning { background: #fffbeb; color: #92400e; }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state i { font-size: 2.5rem; opacity: .4; display: block; margin-bottom: .75rem; }

/* Employee chat */
body.chat-page .container { max-width: 1200px; }

.chat-app {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    min-height: calc(100vh - 220px);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border);
}

.chat-sidebar {
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    min-height: 520px;
}

.chat-sidebar-head {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 340px);
}

.chat-conv-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem 1rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border);
    transition: background .15s;
    position: relative;
}

.chat-conv-item:hover { background: #eef2f7; }
.chat-conv-item.active { background: #e0f2fe; }
.chat-conv-item.unread { background: #fff; }

.chat-conv-body { flex: 1; min-width: 0; }
.chat-conv-preview {
    display: block;
    font-size: .82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-time { font-size: .72rem; white-space: nowrap; }
.chat-unread-dot { position: absolute; left: .5rem; top: 50%; transform: translateY(-50%); font-size: .65rem; }

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-avatar-lg { width: 48px; height: 48px; font-size: 1.1rem; }

.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 520px;
    background: #fff;
}

.chat-main-head {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .85rem;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    max-height: calc(100vh - 380px);
    min-height: 280px;
}

.chat-msg { display: flex; flex-direction: column; max-width: 78%; }
.chat-msg.mine { align-self: flex-start; }
.chat-msg.theirs { align-self: flex-end; }

.chat-msg-author {
    font-size: .72rem;
    color: var(--text-muted);
    margin-bottom: .2rem;
    padding-inline: .35rem;
}

.chat-bubble {
    padding: .65rem .9rem;
    border-radius: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.chat-msg.mine .chat-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.theirs .chat-bubble {
    background: #e2e8f0;
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-msg-time {
    font-size: .68rem;
    color: var(--text-muted);
    margin-top: .25rem;
    padding-inline: .35rem;
}

.chat-compose {
    display: flex;
    gap: .65rem;
    align-items: flex-end;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: #fff;
}

.chat-input {
    resize: none;
    border-radius: var(--radius-sm);
    min-height: 44px;
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-placeholder,
.chat-empty-thread,
.chat-empty-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.chat-placeholder i,
.chat-empty-thread i,
.chat-empty-side i {
    font-size: 3rem;
    opacity: .35;
    margin-bottom: .75rem;
}

.chat-contact-menu {
    max-height: 280px;
    overflow-y: auto;
}

.chat-contact-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    white-space: normal;
}

.chat-back { margin-left: .25rem; }

@media (max-width: 768px) {
    .chat-app { grid-template-columns: 1fr; min-height: calc(100vh - 180px); }
    .chat-sidebar { display: block; }
    .chat-main { display: none; }
    .chat-app--open .chat-sidebar { display: none; }
    .chat-app--open .chat-main { display: flex; }
    .chat-messages { max-height: calc(100vh - 280px); }
    .chat-conv-list { max-height: calc(100vh - 260px); }
    .items-table-wrap { overflow-x: auto; }
    .items-table { min-width: 560px; }
    .page-header .btn { width: 100%; margin-top: .5rem; }
}
