* {
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --dark: #111827;
    --muted: #6b7280;
    --bg: #f4f7fb;
    --white: #ffffff;
    --border: #e5e7eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --purple: #7c3aed;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--dark);
}

a {
    text-decoration: none;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 270px;
    background: #0f172a;
    color: white;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    padding: 22px;
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.brand-icon,
.auth-logo {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.brand strong {
    display: block;
    font-size: 16px;
}

.brand span {
    display: block;
    color: #cbd5e1;
    font-size: 12px;
    margin-top: 2px;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.sidebar-nav a,
.logout-link {
    color: #dbeafe;
    padding: 12px 14px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: 0.2s;
}

.sidebar-nav a:hover,
.logout-link:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}

.sidebar-footer {
    margin-top: auto;
}

.main {
    margin-left: 270px;
    width: calc(100% - 270px);
    min-height: 100vh;
}

.topbar {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 20px 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
}

.topbar p {
    margin: 4px 0 0;
    color: var(--muted);
}

.menu-toggle {
    display: none;
    border: 0;
    background: var(--primary);
    color: white;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 18px;
}

.content {
    padding: 28px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.stat-card,
.panel {
    background: white;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

.stat-card {
    padding: 22px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 10px;
}

.stat-card strong {
    font-size: 28px;
}

.stat-card.highlight {
    border-color: rgba(37, 99, 235, 0.25);
    background: #eff6ff;
}

.stat-card.success {
    border-color: rgba(22, 163, 74, 0.25);
    background: #f0fdf4;
}

.panel {
    padding: 22px;
}

.panel h2 {
    margin: 0 0 14px;
    font-size: 20px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

th {
    text-align: left;
    font-size: 13px;
    color: var(--muted);
    background: #f9fafb;
    padding: 13px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-size: 14px;
}

small {
    color: var(--muted);
}

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 14px;
    outline: none;
    background: white;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.btn {
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    gap: 6px;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

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

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

.btn-success {
    background: var(--success);
}

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

.btn-dark {
    background: #111827;
}

.btn-sm {
    padding: 8px 11px;
    border-radius: 10px;
    font-size: 13px;
}

.w-100 {
    width: 100%;
}

.link {
    color: var(--primary);
    font-weight: 700;
}

.badge {
    display: inline-flex;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

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

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-primary {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-purple {
    background: #ede9fe;
    color: #5b21b6;
}

.badge-dark {
    background: #e5e7eb;
    color: #111827;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

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

.badge-secondary {
    background: #f3f4f6;
    color: #374151;
}

.alert {
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 18px;
    font-weight: 700;
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
}

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .18), transparent 28%),
        radial-gradient(circle at bottom right, rgba(124, 58, 237, .18), transparent 28%),
        #f8fafc;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: white;
    padding: 32px;
    border-radius: 22px;
    box-shadow: 0 20px 70px rgba(15, 23, 42, 0.12);
    border: 1px solid var(--border);
}

.auth-card h2 {
    margin: 18px 0 6px;
}

.auth-card p {
    margin: 0 0 24px;
    color: var(--muted);
}

.auth-link {
    margin-top: 18px;
    text-align: center;
    color: var(--muted);
}

.auth-link a {
    color: var(--primary);
    font-weight: 800;
}

.detail-list {
    display: grid;
    gap: 14px;
}

.detail-list div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.detail-list span {
    color: var(--muted);
}

.detail-list strong {
    text-align: right;
}

.timeline {
    display: grid;
    gap: 12px;
}

.timeline-item {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #f9fafb;
}

.timeline-item strong,
.timeline-item span,
.timeline-item small {
    display: block;
}

.timeline-item span {
    margin: 5px 0;
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.action-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mt-20 {
    margin-top: 20px;
}

.text-center {
    text-align: center;
}

.muted {
    color: var(--muted);
}

@media (max-width: 1100px) {
    .cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: 0.25s;
    }

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

    .main {
        margin-left: 0;
        width: 100%;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .content {
        padding: 18px;
    }

    .topbar {
        padding: 16px 18px;
    }

    .topbar h1 {
        font-size: 20px;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

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

    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-list div {
        flex-direction: column;
    }

    .detail-list strong {
        text-align: left;
    }
}

/* ===============================
   MOBILE LOGO FIX
================================ */

.mobile-logo {
    display: none;
}

.mobile-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

@media (max-width: 768px) {
    .login-brand-section {
        display: none !important;
    }

    .mobile-logo {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 105px;
        height: 105px;
        margin: 0 auto 22px;
        padding: 8px;
        border-radius: 24px;
        background: #ffffff;
        border: 1px solid #e5e7eb;
        box-shadow: 0 16px 35px rgba(15, 23, 42, 0.12);
        overflow: hidden;
    }

    .mobile-logo img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: 18px;
    }

    .login-card {
        padding-top: 26px;
    }
}

@media (max-width: 480px) {
    .mobile-logo {
        width: 88px;
        height: 88px;
        margin-bottom: 18px;
        border-radius: 20px;
    }

    .mobile-logo img {
        border-radius: 15px;
    }
}

.invoice-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.invoice-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.invoice-card {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 18px;
}

.invoice-card h3 {
    margin: 0 0 12px;
    color: #0f172a;
}

.invoice-card p {
    margin: 6px 0;
}

.text-right {
    text-align: right;
}

@media print {
    body {
        background: #ffffff !important;
    }

    .sidebar,
    .topbar,
    .invoice-actions,
    .btn {
        display: none !important;
    }

    .main-content,
    .content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .panel,
    .invoice-box {
        box-shadow: none !important;
        border: 0 !important;
        padding: 0 !important;
    }

    table {
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}

.chat-box {
    min-height: 320px;
    max-height: 520px;
    overflow-y: auto;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-message {
    width: fit-content;
    max-width: 72%;
    padding: 14px 16px;
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.chat-message.mine {
    margin-left: auto;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    border-bottom-right-radius: 6px;
}

.chat-message.other {
    margin-right: auto;
    background: #ffffff;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 6px;
}

.chat-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 7px;
}

.chat-meta strong {
    font-size: 13px;
}

.chat-meta small {
    font-size: 11px;
    opacity: 0.75;
}

.chat-message p {
    margin: 0;
    line-height: 1.6;
    font-size: 14px;
}

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

@media (max-width: 768px) {
    .chat-message {
        max-width: 88%;
    }

    .chat-box {
        max-height: 440px;
        padding: 14px;
    }
}