/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 240px;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-100);
}

.login-container { width: 100%; max-width: 400px; padding: 1rem; }

.login-card {
    background: white;
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    text-align: center;
}

.login-card h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    color: var(--gray-900);
}

/* === App Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--gray-700);
}

.sidebar-logo {
    height: 28px;
    width: auto;
}

.nav-menu {
    list-style: none;
    flex: 1;
    padding: .5rem 0;
    overflow-y: auto;
}

.nav-menu li a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    color: var(--gray-300);
    font-size: .875rem;
    transition: background .15s, color .15s;
    text-decoration: none;
}

.nav-menu li a:hover,
.nav-menu li a.active {
    background: var(--gray-700);
    color: white;
    text-decoration: none;
}

.nav-icon { font-size: .5rem; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--gray-700);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .8rem;
}

.btn-logout {
    color: var(--gray-400);
    font-size: .8rem;
}

/* === Main Content === */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 1.5rem 2rem;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.content-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* === Alerts === */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .875rem;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

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

.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }

.btn-outline {
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); }

.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

/* === Forms === */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: .35rem;
    font-weight: 500;
    font-size: .875rem;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: inherit;
    transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-group textarea { resize: vertical; min-height: 80px; }

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

.form-actions {
    display: flex;
    gap: .75rem;
    margin-top: 1.5rem;
}

/* === Tables === */
.table-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: .75rem 1rem;
    text-align: left;
    font-size: .875rem;
}

thead th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 1px solid var(--gray-200);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
}

tbody tr { border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child { border-bottom: none; }

.table-actions {
    display: flex;
    gap: .5rem;
}

/* === Cards === */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* === Company Tiles === */
.company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.company-tile {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s, transform .15s;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.company-tile:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    transform: translateY(-2px);
    text-decoration: none;
}

.company-tile-header {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.company-logo {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: contain;
    flex-shrink: 0;
    background: var(--gray-50);
}

.company-logo-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.company-tile-info {
    min-width: 0;
}

.company-tile-info h3 {
    font-size: .9rem;
    font-weight: 600;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.company-tile-meta {
    font-size: .75rem;
    color: var(--gray-400);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.company-tile-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: .5rem;
    border-top: 1px solid var(--gray-100);
}

/* === Star Button === */
.star-form { display: inline; }

.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--gray-300);
    transition: color .15s, transform .15s;
    padding: 0;
    line-height: 1;
}

.star-btn:hover {
    color: #f59e0b;
    transform: scale(1.15);
}

.star-btn.active {
    color: #f59e0b;
}

.company-tile.starred {
    border: 2px solid #fbbf24;
}

.company-tile:not(.starred) {
    border: 2px solid transparent;
}

/* === Contacts Grouped by Company === */
.contacts-grouped {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.contact-company-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    overflow: hidden;
}

.contact-company-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 1.25rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
    gap: .5rem;
}

.contact-company-title {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 600;
    font-size: .95rem;
}

.contact-company-title a {
    color: var(--gray-900);
}

.contact-company-title a:hover {
    color: var(--primary);
}

.contact-company-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: wrap;
}

.company-logo-sm {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    object-fit: contain;
    background: white;
    flex-shrink: 0;
}

.company-logo-placeholder-sm {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .8rem;
    flex-shrink: 0;
}

.contact-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0;
}

.contact-tile {
    padding: 1rem 1.25rem;
    border-right: 1px solid var(--gray-100);
    border-bottom: 1px solid var(--gray-100);
}

.contact-tile-name {
    font-weight: 500;
    font-size: .875rem;
    margin-bottom: .2rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.contact-tile-name a {
    color: var(--gray-900);
}

.contact-tile-name a:hover {
    color: var(--primary);
}

.contact-tile-role {
    font-size: .75rem;
    color: var(--gray-400);
    margin-bottom: .4rem;
}

.contact-tile-details {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    margin-bottom: .5rem;
}

.contact-tile-meta {
    font-size: .75rem;
    color: var(--gray-500);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

a.contact-tile-meta:hover {
    color: var(--primary);
}

.contact-tile-actions {
    display: flex;
    gap: .4rem;
}

/* === Project Cards === */
.project-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.project-card {
    background: white;
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.project-card-main {
    min-width: 0;
    flex: 1;
}

.project-card-title {
    font-weight: 500;
    font-size: .95rem;
    margin-bottom: .3rem;
}

.project-card-title a {
    color: var(--gray-900);
}

.project-card-title a:hover {
    color: var(--primary);
}

.project-card-meta {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.project-card-company {
    font-size: .8rem;
    color: var(--gray-500);
}

.project-card-company:hover {
    color: var(--primary);
}

.project-card-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.project-card-budget {
    font-weight: 600;
    font-size: .95rem;
    color: var(--gray-700);
    white-space: nowrap;
}

/* === Finance Tracker (Project) === */
.finance-tracker {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    margin-bottom: 1.5rem;
}

.finance-tracker-bar {
    height: 12px;
    background: var(--gray-100);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    margin-bottom: 1rem;
}

.finance-tracker-paid {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: var(--success);
    border-radius: 6px 0 0 6px;
    z-index: 2;
    transition: width .3s;
}

.finance-tracker-invoiced {
    position: absolute;
    top: 0; bottom: 0;
    background: var(--warning);
    z-index: 1;
    transition: width .3s;
    left: 0;
}

.finance-tracker-stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.finance-tracker-stat {
    display: flex;
    align-items: center;
    gap: .4rem;
}

.finance-tracker-label {
    font-size: .75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .3px;
}

.finance-tracker-value {
    font-size: .95rem;
    font-weight: 600;
    color: var(--gray-800);
}

.finance-tracker-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-paid { background: var(--success); }
.dot-outstanding { background: var(--warning); }
.dot-draft { background: var(--gray-300); }

/* === Progress Bar (compact, for project list) === */
.progress-bar {
    height: 6px;
    background: var(--gray-100);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
    width: 100px;
}

.progress-bar-paid {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: var(--success);
    border-radius: 3px 0 0 3px;
    z-index: 2;
}

.progress-bar-invoiced {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: var(--warning);
    z-index: 1;
}

.project-card-finance {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .3rem;
}

.project-finance-numbers {
    font-size: .8rem;
    white-space: nowrap;
}

.project-finance-paid {
    font-weight: 600;
    color: var(--success);
}

.project-finance-sep {
    color: var(--gray-300);
    margin: 0 .15rem;
}

.project-finance-budget {
    color: var(--gray-500);
}

/* === Inline Select (invoice project assign) === */
.inline-select {
    padding: .25rem .5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: .75rem;
    color: var(--gray-600);
    background: var(--gray-50);
    cursor: pointer;
    max-width: 180px;
}

.inline-select:focus {
    outline: none;
    border-color: var(--primary);
}

.invoice-project-form {
    display: inline;
}

/* === Checkbox Grid === */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .4rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .875rem;
    font-weight: 400;
    cursor: pointer;
    padding: .3rem .5rem;
    border-radius: var(--radius);
    transition: background .1s;
}

.checkbox-label:hover {
    background: var(--gray-50);
}

/* === Stats Grid (Dashboard) === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.stat-card .stat-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-500);
    margin-bottom: .25rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-card .stat-sub {
    font-size: .8rem;
    color: var(--gray-400);
    margin-top: .25rem;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 500;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fffbeb; color: #92400e; }
.badge-danger  { background: #fef2f2; color: #991b1b; }
.badge-info    { background: #eff6ff; color: #1e40af; }
.badge-gray    { background: var(--gray-100); color: var(--gray-600); }

/* === Detail View === */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.detail-section { margin-bottom: 1.5rem; }

.detail-row {
    display: flex;
    padding: .5rem 0;
    border-bottom: 1px solid var(--gray-100);
}

.detail-label {
    width: 140px;
    font-weight: 500;
    color: var(--gray-500);
    font-size: .8rem;
    flex-shrink: 0;
}

.detail-value {
    color: var(--gray-800);
    font-size: .875rem;
}

/* === Task-specific === */
.task-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
}

.task-item:last-child { border-bottom: none; }

.task-item.done { opacity: .5; }
.task-item.done .task-title { text-decoration: line-through; }

.task-title { flex: 1; font-size: .875rem; }
.task-meta { font-size: .75rem; color: var(--gray-400); }

/* === Finance Summary === */
.finance-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* === Tabs === */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1.5rem;
}

.tab {
    padding: .6rem 1.25rem;
    font-size: .875rem;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    text-decoration: none;
}

.tab:hover { color: var(--gray-700); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
}

.empty-state p { margin-bottom: 1rem; }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
}
