:root {
    --bg: #f2f5fb;
    --surface: #ffffff;
    --surface-soft: #f8faff;
    --border: #d7dfec;
    --text: #0f172a;
    --text-muted: #475569;
    --primary: #1e3a8a;
    --primary-strong: #172554;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --shadow-soft: 0 10px 26px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #111b31;
        --surface-soft: #16233e;
        --border: #26344f;
        --text: #e5edff;
        --text-muted: #9fb0ce;
        --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.35);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg) 0%, #ecf2fb 100%);
    color: var(--text);
}

h1, h2, h3 {
    margin: 0;
    letter-spacing: -0.2px;
}

h2 {
    font-size: 1.45rem;
}

label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 8px;
}

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

.sidebar {
    width: 258px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
}

.brand {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 20px;
    padding: 8px 10px;
}

.sidebar-head {
    display: block;
}

.menu-toggle {
    display: none;
    align-items: center;
    gap: 8px;
    width: auto;
    margin: 0;
    padding: 8px 10px;
    font-size: 0.82rem;
    border-radius: 8px;
}

.nav a {
    display: flex;
    position: relative;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #334155;
    text-decoration: none;
    margin-bottom: 6px;
    font-weight: 600;
}

.nav a:hover,
.nav a.active {
    background: #eef4ff;
    color: var(--primary);
}

.nav a i {
    width: 16px;
    text-align: center;
    opacity: 0.9;
}

.menu-alert {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 800;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.25);
    flex-shrink: 0;
}

.top-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

.content {
    flex: 1;
    padding: 24px;
}

.top-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
}

.top-actions div {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-soft);
}

.kpi-title {
    color: var(--text-muted);
    font-size: 0.84rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-title i {
    margin-right: 6px;
    color: #2563eb;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.section-head h3 {
    font-size: 1.05rem;
    color: var(--text);
}

.section-head h3 i {
    color: #1e40af;
    margin-right: 6px;
}

.progress-wrap {
    margin-top: 10px;
}

.progress-track {
    width: 100%;
    height: 9px;
    background: #dbe6fa;
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1e40af, #2563eb);
    border-radius: 999px;
    transition: width .25s ease;
}

.timeline {
    margin-top: 10px;
    border-left: 2px solid #d8e2f2;
    padding-left: 12px;
}

.timeline-item {
    position: relative;
    padding: 8px 0 8px 6px;
}

.timeline-item::before {
    content: "";
    position: absolute;
    left: -19px;
    top: 14px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2563eb;
}

.timeline-meta {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat {
    font-size: 1.95rem;
    font-weight: 800;
    color: var(--primary);
    margin-top: 6px;
}

.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: "";
    position: absolute;
    right: -20px;
    bottom: -24px;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.16) 0%, rgba(37, 99, 235, 0) 70%);
}

.project-card {
    border-left: 4px solid #1e40af;
}

.project-rules {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-soft);
    border: 1px solid #dde7f6;
}

.project-timer {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.project-countdown {
    margin-left: 2px;
    font-variant-numeric: tabular-nums;
}

.countdown-live {
    color: #166534;
}

.countdown-warning {
    color: #92400e;
}

.countdown-danger {
    color: #991b1b;
}

.countdown-muted {
    color: #64748b;
}

.milestone-card {
    border-left: 4px solid #0f4c81;
}

.milestone-meta {
    background: var(--surface-soft);
    border: 1px solid #dce6f4;
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 0.9rem;
}

.milestone-meta i {
    color: #1d4ed8;
    margin-right: 6px;
}

.invoice-panel {
    margin-top: 12px;
    border: 1px solid #d9e3f3;
    border-radius: 12px;
    background: linear-gradient(180deg, #f9fbff 0%, #f3f7ff 100%);
    padding: 12px;
}

.invoice-grid {
    margin-top: 8px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    align-items: stretch;
}

.invoice-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: #ffffff;
    border: 1px solid #dce6f4;
    border-radius: 10px;
    padding: 8px 10px;
    min-width: 0;
}

.invoice-item i {
    color: #1d4ed8;
    margin-top: 2px;
}

.invoice-item small {
    display: block;
    color: var(--text-muted);
    font-size: 0.72rem;
    margin-bottom: 2px;
}

.invoice-item strong {
    display: block;
    font-size: 0.84rem;
    color: #0f172a;
}

.invoice-break {
    word-break: break-all;
    overflow-wrap: anywhere;
}

.tx-hash {
    margin-top: 10px;
    display: block;
}

.invoice-table th:nth-child(1),
.invoice-table td:nth-child(1) {
    width: 130px;
}

.invoice-table th:nth-child(4),
.invoice-table td:nth-child(4) {
    min-width: 220px;
}

.invoice-table th:nth-child(5),
.invoice-table td:nth-child(5) {
    min-width: 280px;
}

.invoice-wallet-cell i,
.invoice-tx-cell i {
    color: #1d4ed8;
    margin-right: 4px;
}

.invoice-tx-form {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 8px;
    align-items: end;
}

.invoice-tx-form input,
.invoice-tx-form button {
    margin-top: 0;
}

.ring-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 10px;
}

.progress-ring {
    --pct: 0;
    width: 94px;
    height: 94px;
    border-radius: 50%;
    background: conic-gradient(#2563eb calc(var(--pct) * 1%), #dbe7fb 0);
    display: grid;
    place-items: center;
}

.ring-center {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--surface);
    display: grid;
    place-items: center;
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--primary);
}

.mini-bars {
    margin-top: 10px;
    display: grid;
    gap: 10px;
}

.mini-bar {
    display: grid;
    grid-template-columns: 92px 1fr;
    align-items: center;
    gap: 8px;
}

.mini-bar span {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.mini-bar .bar {
    height: 8px;
    background: #e3ebfa;
    border-radius: 999px;
    overflow: hidden;
}

.mini-bar .bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #1e40af, #2563eb);
    border-radius: 999px;
}

table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 10px;
}

th,
td {
    text-align: left;
    border-bottom: 1px solid #e6ecf5;
    padding: 11px 9px;
    font-size: 0.9rem;
    vertical-align: top;
}

th {
    color: #334155;
    background: var(--surface-soft);
    font-weight: 700;
}

input,
textarea,
select,
button {
    width: 100%;
    padding: 10px 11px;
    border: 1px solid #c9d3e5;
    border-radius: 9px;
    box-sizing: border-box;
    margin-top: 6px;
    font-family: inherit;
    font-size: 0.92rem;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

button {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 700;
}

button:hover {
    filter: brightness(1.06);
}

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

.badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.pending {
    background: #fef3c7;
    color: #92400e;
}

.approved,
.open {
    background: #dbeafe;
    color: #1e3a8a;
}

.paid {
    background: #dcfce7;
    color: #166534;
}

.submitted,
.proposal_sent,
.negotiation {
    background: #fef3c7;
    color: #92400e;
}

.in-progress {
    background: #fef3c7;
    color: #92400e;
}

.in_progress {
    background: #fef3c7;
    color: #92400e;
}

.progress {
    background: #fef3c7;
    color: #92400e;
}

.completed,
.closed {
    background: #dcfce7;
    color: #166534;
}

.rejected {
    background: #fee2e2;
    color: #991b1b;
}

.cancelled,
.canceled {
    background: #fee2e2;
    color: #991b1b;
}

.accepted {
    background: #dbeafe;
    color: #1e3a8a;
}

.unpaid {
    background: #fef3c7;
    color: #92400e;
}

.ticket-type {
    margin-right: 6px;
    text-transform: capitalize;
}

.ticket-type.tech {
    background: #e0f2fe;
    color: #0c4a6e;
}

.ticket-type.normal {
    background: #e2e8f0;
    color: #334155;
}

.ticket-type.urgent {
    background: #fee2e2;
    color: #991b1b;
}

.chat-box {
    height: 340px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: var(--surface);
}

.msg {
    margin-bottom: 8px;
    padding: 9px 11px;
    border-radius: 9px;
    background: #f1f5f9;
    color: #0f172a;
}

.msg.admin {
    background: #dbeafe;
}

.msg.client {
    background: #ecfeff;
}

.chat-shell {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fbff;
    overflow: hidden;
}

.chat-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: #eef4ff;
}

.chat-head small {
    color: #475569;
    font-weight: 600;
}

.chat-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    margin-right: 6px;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
    animation: chatPulse 1.8s infinite;
}

@keyframes chatPulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.chat-messages {
    background: linear-gradient(180deg, #f8fbff 0%, #f1f7ff 100%);
    padding: 12px;
    height: 360px;
}

.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 10px;
}

.chat-row.me {
    justify-content: flex-end;
}

.chat-row.other {
    justify-content: flex-start;
}

.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
}

.chat-row.me .chat-avatar {
    order: 2;
    background: #dbeafe;
    color: #1e3a8a;
}

.chat-row.other .chat-avatar {
    background: #e2e8f0;
    color: #334155;
}

.chat-bubble {
    max-width: min(78%, 560px);
    border-radius: 12px;
    padding: 9px 11px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
}

.chat-row.me .chat-bubble {
    background: #1e3a8a;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-row.other .chat-bubble {
    background: #ffffff;
    color: #0f172a;
    border: 1px solid #dce6f4;
    border-bottom-left-radius: 4px;
}

.chat-text {
    line-height: 1.5;
}

.chat-meta {
    margin-top: 4px;
    font-size: 0.74rem;
    opacity: 0.85;
}

.chat-composer {
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.chat-composer textarea {
    min-height: 48px;
    max-height: 120px;
    resize: vertical;
}

.chat-composer button {
    width: 110px;
}

.chat-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-actions button {
    width: 130px;
}

.chat-actions #sendBtn {
    background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
}

.chat-chips {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-chips a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #e8f0ff;
    color: #1e3a8a;
    border: 1px solid #cfe0ff;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
}

.chat-chips a:hover {
    background: #dbeafe;
}

.ticket-thread {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.flash {
    padding: 11px 12px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 0.9rem;
}

.flash.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.flash.error {
    background: var(--error-bg);
    color: var(--error-text);
}

@media (max-width: 1024px) {
    .content {
        padding: 18px;
    }
}

@media (max-width: 900px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 10px;
    }

    .top-actions {
        flex-direction: column;
        align-items: flex-start;
    }

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

    .sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }

    .brand {
        margin-bottom: 0;
    }

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

    .nav {
        display: none;
        margin-top: 10px;
        flex-direction: column;
        gap: 6px;
        overflow: visible;
        padding-bottom: 0;
    }

    .sidebar.open .nav {
        display: flex;
    }

    .nav a {
        flex: 1 1 auto;
        margin-bottom: 0;
        white-space: normal;
        min-height: 42px;
    }

    .ring-wrap {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-head {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 640px) {
    .content {
        padding: 14px;
    }

    .card {
        padding: 14px;
        border-radius: 12px;
    }

    .top-actions h2 {
        font-size: 1.15rem;
    }

    .top-user {
        flex-wrap: wrap;
        row-gap: 6px;
    }

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

    th,
    td {
        font-size: 0.82rem;
        padding: 9px 7px;
    }

    .stat {
        font-size: 1.7rem;
    }

    .card table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

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

    .invoice-table th:nth-child(4),
    .invoice-table td:nth-child(4),
    .invoice-table th:nth-child(5),
    .invoice-table td:nth-child(5) {
        min-width: 200px;
    }

    .chat-messages {
        height: 300px;
    }

    .chat-bubble {
        max-width: 90%;
    }

    .chat-composer {
        grid-template-columns: 1fr;
    }

    .chat-composer button {
        width: 100%;
    }

    .chat-actions {
        flex-direction: row;
        width: 100%;
    }

    .chat-actions button {
        width: 100%;
    }

    .nav a {
        padding: 9px 10px;
        font-size: 0.78rem;
        border-radius: 8px;
        gap: 8px;
    }

    .menu-alert {
        min-width: 18px;
        height: 18px;
        font-size: 0.66rem;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 11px;
    }

    .brand {
        font-size: 1rem;
        padding: 6px 8px;
    }

    .menu-toggle {
        padding: 7px 9px;
        font-size: 0.76rem;
    }

    .nav a {
        padding: 8px 9px;
        font-size: 0.74rem;
    }

    .kpi-title {
        font-size: 0.76rem;
    }

    .stat {
        font-size: 1.45rem;
    }

    .section-head h3 {
        font-size: 0.96rem;
    }

    .milestone-meta,
    .project-rules,
    .timeline-meta {
        font-size: 0.8rem;
    }
}

/* Auth pages */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #edf2fb 0%, #e3ebf8 55%, #f5f8fd 100%);
}

.auth-wrap {
    max-width: 460px;
    margin: 48px auto;
    padding: 0 14px;
}

.auth-card {
    border-radius: 16px;
    padding: 24px;
    border: 1px solid #cdd9ee;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.1);
}

.auth-card h2 {
    font-size: 1.45rem;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
    color: #0f172a;
}

.auth-brand {
    display: inline-block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #1e3a8a;
    font-weight: 700;
    background: #e8efff;
    border: 1px solid #d1ddf7;
    border-radius: 999px;
    padding: 6px 10px;
}

.auth-subtitle {
    margin: 8px 0 16px;
    color: #5b6b83;
    font-size: 0.88rem;
    line-height: 1.5;
}

.auth-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    color: #334155;
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.auth-label i {
    color: #1d4ed8;
    width: 12px;
    text-align: center;
}

.auth-card input {
    margin-top: 0;
}

.auth-card button i {
    margin-right: 6px;
}

.auth-links {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-links a {
    color: #1e3a8a;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.86rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.auth-links a:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    .auth-wrap {
        margin: 26px auto;
    }

    .auth-card {
        padding: 16px;
    }
}
