@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #f3f5f9;
    --panel: #ffffff;
    --border: #e6e9f0;
    --text: #1a2233;
    --muted: #6b7385;
    --primary: #1d4ed8;
    --primary-dark: #1741b0;
    --primary-light: #3b7cf5;
    --primary-tint: #eaf0fe;
    --navy: #0a0c12;
    --navy-soft: #12151f;
    --success: #16a34a;
    --success-tint: #e9f9ee;
    --danger: #ef4444;
    --danger-tint: #fef2f2;
    --warning: #f59e0b;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(20, 26, 42, 0.05);
    --shadow: 0 4px 16px rgba(20, 26, 42, 0.06), 0 1px 3px rgba(20, 26, 42, 0.05);
    --shadow-lg: 0 12px 32px rgba(20, 26, 42, 0.1), 0 2px 6px rgba(20, 26, 42, 0.06);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary-light); color: #fff; }

a { color: var(--primary); }

.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

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

/* Sidebar */
.sidebar {
    width: 240px;
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-soft) 100%);
    color: #aab2c5;
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; padding: 4px 10px; }
.brand-mark {
    width: 32px;
    height: 32px;
    display: block;
    flex-shrink: 0;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(29, 78, 216, 0.35);
}
.brand-name { font-weight: 700; font-size: 15px; color: #fff; text-transform: uppercase; letter-spacing: 0.06em; }

.nav-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #545c72; padding: 0 12px; margin: 4px 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    color: #aab2c5;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav a .icon { opacity: 0.8; }
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav a.active { background: rgba(29,78,216,0.22); color: #fff; border-left-color: var(--primary-light); }
.nav a.active .icon { opacity: 1; color: var(--primary-light); }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 14px; margin-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 0 4px; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(59,124,245,0.18); color: #cfe0ff;
    display: flex; align-items: center; justify-content: center;
    font-size: 12.5px; font-weight: 700; flex-shrink: 0;
    border: 1px solid rgba(59,124,245,0.35);
}
.user-chip .name { font-size: 13.5px; color: #e7eaf3; font-weight: 600; line-height: 1.2; }
.user-chip .role { font-size: 11.5px; color: #6b7385; }
.logout-link {
    display: flex; align-items: center; gap: 8px;
    color: #a9b2c8; text-decoration: none; font-size: 13px; font-weight: 500;
    padding: 8px 4px; border-radius: var(--radius-sm);
    transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.logout-link:hover { color: #ff9c9c; background: rgba(239,68,68,0.08); }

/* Content */
.content { flex: 1; padding: 32px 40px; max-width: 1280px; animation: fade-in 0.25s var(--ease); }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 26px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 23px; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.page-header p.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 17px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff;
    box-shadow: 0 1px 2px rgba(29,78,216,0.2), 0 1px 1px rgba(29,78,216,0.12) inset;
    transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease), border-color 0.15s var(--ease);
}
.btn:hover { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 8px 20px rgba(29,78,216,0.32); transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: 0 2px 6px rgba(29,78,216,0.25); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(29,78,216,0.25); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-outline:hover { background: var(--primary-tint); border-color: var(--primary-light); color: var(--primary-dark); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn-danger { background: linear-gradient(135deg, #f87171, var(--danger)); box-shadow: 0 1px 2px rgba(239,68,68,0.2); }
.btn-danger:hover { background: linear-gradient(135deg, var(--danger), #dc2626); box-shadow: 0 8px 20px rgba(239,68,68,0.32); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

/* Cards / stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.stat-card .label { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.stat-card .value { font-size: 25px; font-weight: 800; letter-spacing: -0.01em; }
.stat-icon {
    width: 42px; height: 42px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-tint); color: var(--primary); }
.stat-icon.green { background: var(--success-tint); color: var(--success); }
.stat-icon.amber { background: #fef6e7; color: var(--warning); }
.stat-icon.violet { background: #f1edff; color: #7c3aed; }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-header h2 { margin: 0; font-size: 16px; font-weight: 700; }

/* Project payment progress */
.progress-track { background: #eef1f6; border-radius: 20px; height: 10px; overflow: hidden; }
.progress-fill { background: linear-gradient(90deg, var(--primary-light), var(--primary)); height: 100%; border-radius: 20px; transition: width 0.3s var(--ease); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; margin: 14px 0; }
.summary-item .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.summary-item .value { font-size: 19px; font-weight: 700; }
.summary-item .value.accent { color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; margin: -4px -4px 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
th, td { text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; background: #fafbfd; }
th:first-child { border-top-left-radius: var(--radius-sm); }
th:last-child { border-top-right-radius: var(--radius-sm); }
tbody tr { transition: background 0.12s var(--ease); }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; }
.cell-primary { font-weight: 600; }
.cell-with-avatar { display: flex; align-items: center; gap: 10px; }
.row-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--primary-tint); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 11.5px; font-weight: 700; flex-shrink: 0;
}

.badge { display: inline-flex; align-items: center; padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; margin-right: 6px; flex-shrink: 0; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: #fbfcfe;
    color: var(--text);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
.form-group input:hover, .form-group select:hover, .form-group textarea:hover { border-color: #cbd5e1; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(29,78,216,0.12);
}
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* Flash messages */
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 20px;
    font-size: 14px; font-weight: 500;
    animation: flash-in 0.25s var(--ease);
    box-shadow: var(--shadow-sm);
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.flash-success { background: var(--success-tint); color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: var(--danger-tint); color: #991b1b; border: 1px solid #fecaca; }
.flash .icon { flex-shrink: 0; }

/* Chip multi-select (e.g. "Services this client receives") */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-checkbox { position: relative; }
.chip-checkbox input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip-checkbox span {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
    border: 1px solid var(--border); background: #fff; color: var(--muted);
    cursor: pointer; transition: all 0.15s var(--ease); user-select: none;
}
.chip-checkbox:hover span { border-color: #cbd5e1; color: var(--text); }
.chip-checkbox input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(29,78,216,0.25); }
.chip-checkbox input:focus-visible + span { outline: 2px solid var(--primary-light); outline-offset: 2px; }
.service-chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; background: var(--primary-tint); color: var(--primary); margin: 2px 4px 2px 0; }

/* Login page */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 15% 20%, rgba(29,78,216,0.35), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(59,124,245,0.22), transparent 50%),
        linear-gradient(180deg, var(--navy) 0%, var(--navy-soft) 100%);
    padding: 20px;
}
.login-box {
    background: #fff; padding: 40px; border-radius: var(--radius-lg); width: 380px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.4);
    animation: fade-in 0.3s var(--ease);
}
.login-logo { display: block; height: 32px; width: auto; margin: 0 auto 26px; }
.login-box h1 { font-size: 21px; margin: 0 0 4px; font-weight: 800; letter-spacing: -0.01em; text-align: center; }
.login-box h1 span { color: var(--primary); }
.login-box p { color: var(--muted); font-size: 14px; margin: 0 0 24px; text-align: center; }
.login-box .btn { justify-content: center; padding: 11px 16px; }
.login-foot { text-align: center; font-size: 12.5px; color: #7c8499; margin-top: 20px; }
.login-foot a { color: var(--primary-light); font-weight: 600; text-decoration: none; }
.login-foot a:hover { text-decoration: underline; }

/* Invoice line items */
.line-items-table input, .line-items-table select { padding: 8px 9px; font-size: 13px; }
.line-items-table th { white-space: nowrap; }
.remove-row {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; color: var(--muted); cursor: pointer;
    background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
    transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.remove-row:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-tint); }
.totals-box { max-width: 320px; margin-left: auto; margin-top: 18px; background: #fafbfd; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; color: var(--muted); }
.totals-row.grand { font-size: 18px; font-weight: 800; color: var(--text); border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }

.empty-state { text-align: center; padding: 64px 20px; color: var(--muted); }
.empty-state .icon { color: #c3cadb; margin-bottom: 14px; }
.empty-state p { margin: 0 0 4px; font-size: 14.5px; }
.empty-state a { font-weight: 600; }

.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-pills a, .filter-pills button {
    appearance: none; -webkit-appearance: none; outline: none;
    display: inline-flex; align-items: center;
    padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
    font-family: inherit; line-height: normal;
    text-decoration: none; color: var(--muted); border: 1px solid var(--border); background: #fff;
    cursor: pointer;
    transition: all 0.15s var(--ease);
}
.filter-pills a:hover, .filter-pills button:hover { border-color: #cbd5e1; color: var(--text); }
.filter-pills a.active, .filter-pills button.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(29,78,216,0.25); }

/* Segmented control (single-select toggle, e.g. Invoice Type) */
.segmented {
    display: inline-flex; gap: 3px; padding: 4px;
    background: #eef1f6; border-radius: 12px;
}
.segmented button {
    appearance: none; -webkit-appearance: none; outline: none;
    border: none; background: transparent; cursor: pointer;
    padding: 9px 18px; border-radius: 9px;
    font-family: inherit; font-size: 13.5px; font-weight: 600; line-height: normal;
    color: var(--muted);
    transition: all 0.15s var(--ease);
}
.segmented button:hover:not(.active) { color: var(--text); }
.segmented button.active {
    background: #fff; color: var(--primary);
    box-shadow: 0 2px 6px rgba(20,26,42,0.1);
}
@media (max-width: 600px) {
    .segmented { flex-direction: column; width: 100%; }
    .segmented button { width: 100%; }
}

/* Section grouping within a long form (e.g. the invoice form) */
.form-section { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--border); }
.form-section-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--primary); margin: 0 0 18px;
}
.form-section-title::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--primary-light); flex-shrink: 0; }

@media (max-width: 900px) {
    .sidebar { position: static; height: auto; }
    .app { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
    .brand { margin-bottom: 0; }
    .nav-label { display: none; }
    .nav { flex-direction: row; overflow-x: auto; }
    .nav a span:last-child { display: none; }
    .sidebar-footer { display: none; }
    .content { padding: 20px; }
    .form-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
