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

:root {
    --color-bg: #f5f5f0;
    --color-surface: #ffffff;
    --color-text: #2c2c2c;
    --color-muted: #777;
    --color-border: #ddd;
    --color-primary: #3a5a40;
    --color-primary-light: #588157;
    --color-danger: #c1121f;
    --color-flash-success: #d4edda;
    --color-flash-error: #f8d7da;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

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

code {
    background: #eee;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* === Nav === */
.main-nav {
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 48px;
    gap: 0;
}

.nav-brand a {
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.5px;
    white-space: nowrap;
}
.nav-brand a:hover { text-decoration: none; }

.nav-links {
    list-style: none;
    display: flex;
    gap: 0.1rem;
    align-items: center;
    height: 100%;
}

.nav-links a {
    color: rgba(255,255,255,0.85);
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.15s;
    white-space: nowrap;
}
.nav-links a:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
    text-decoration: none;
}
.nav-links a.active {
    background: rgba(255,255,255,0.22);
    color: #fff;
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}
.nav-project-select {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius);
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    max-width: 220px;
}
.nav-project-select:focus {
    outline: none;
    border-color: rgba(255,255,255,0.6);
    background: rgba(255,255,255,0.25);
}
.nav-project-select option {
    background: var(--color-surface);
    color: var(--color-text);
}
.nav-right a {
    color: rgba(255,255,255,0.85);
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.15s;
    white-space: nowrap;
}
.nav-right a:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
    text-decoration: none;
}
.nav-right a.active {
    background: rgba(255,255,255,0.22);
    color: #fff;
}

/* === Sub-nav (modules row) === */
.sub-nav {
    background: var(--color-primary-light);
    padding: 0 1.5rem;
    height: 38px;
    display: flex;
    align-items: center;
}

.sub-nav-links {
    list-style: none;
    display: flex;
    gap: 0.1rem;
    align-items: center;
    height: 100%;
}

.sub-nav-links a {
    color: rgba(255,255,255,0.85);
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    transition: background 0.15s;
    white-space: nowrap;
}
.sub-nav-links a:hover {
    background: rgba(255,255,255,0.18);
    color: #fff;
    text-decoration: none;
}
.sub-nav-links a.active {
    background: rgba(255,255,255,0.25);
    color: #fff;
}

.sub-nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
}

/* === Impersonation bar === */
.impersonation-bar {
    background: #fef3c7;
    color: #92400e;
    padding: 0.4rem 1.5rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid #f59e0b;
}

/* === User menu (top-right) === */
.nav-user-menu {
    position: relative;
}
.nav-user-btn {
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.9);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: var(--radius);
    padding: 0.3rem 0.7rem;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.nav-user-btn:hover {
    background: rgba(255,255,255,0.2);
}
.nav-role-badge {
    background: rgba(255,255,255,0.2);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.nav-user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    min-width: 200px;
    z-index: 1000;
    overflow: hidden;
}
.nav-user-dropdown.show { display: block; }
.nav-user-info {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
}
.nav-user-info strong {
    display: block;
    font-size: 0.9rem;
}
.nav-user-info span {
    display: block;
    font-size: 0.78rem;
    color: var(--color-muted);
}
.nav-user-dropdown-item {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    border: none;
    background: none;
    text-align: left;
    font-size: 0.88rem;
    color: var(--color-text);
    cursor: pointer;
}
.nav-user-dropdown-item:hover {
    background: var(--color-bg);
}

.inline-link-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.inline-link-form select {
    min-width: 200px;
}

/* Trade groups */
.trade-group {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.trade-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.trade-header h3 {
    margin: 0;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.gewerk-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 0;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    line-height: 1;
    flex-shrink: 0;
}
.trade-assign-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.badge-company {
    background: #e0e7ff;
    color: #3730a3;
}
.badge-person {
    background: #dcfce7;
    color: #166534;
}

/* === Content === */
.content {
    max-width: 1100px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}
.content-full {
    max-width: none;
}

/* === Flash Messages === */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
.flash-success { background: var(--color-flash-success); color: #155724; }
.flash-error   { background: var(--color-flash-error);   color: #721c24; }

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; }
.page-actions { display: flex; gap: 0.5rem; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.875rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    box-sizing: border-box;
}
.btn:hover { background: #f0f0f0; text-decoration: none; }

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-light); }

.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn-danger:hover { opacity: 0.9; }

.btn-small { height: 28px; padding: 0 0.65rem; font-size: 0.8rem; }

/* === Data Table === */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.data-table th,
.data-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.875rem;
}

.data-table th {
    background: #fafafa;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--color-muted);
}

.data-table tbody tr:hover { background: #f9f9f6; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* === Badge === */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: #e9ecef;
    color: #495057;
}

/* === Stats Grid (Dashboard) === */
.stats-grid {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--color-surface);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-width: 140px;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #222;
}
.stat-label { font-size: 0.8rem; color: #222; text-transform: uppercase; }

/* === Dashboard Sections === */
.dashboard-section {
    margin-bottom: 2rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.section-header h2 { font-size: 1.1rem; color: #222; }

/* === Module Grid (Dashboard) === */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

.module-card {
    background: var(--color-surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: box-shadow 0.15s;
    color: #222;
}
.module-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); text-decoration: none; }
.module-icon { display: none; }
.module-label { font-weight: 600; font-size: 0.9rem; color: #222; }

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

.detail-card {
    background: var(--color-surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.detail-card h2 { font-size: 0.8rem; margin-bottom: 0.75rem; color: #222; text-transform: uppercase; letter-spacing: 0.3px; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; }
.detail-list dt { font-weight: 600; font-size: 0.85rem; color: var(--color-muted); }
.detail-list dd { font-size: 0.9rem; }

.detail-section { margin-bottom: 2rem; }
.detail-section h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }

.phase-list { list-style: none; }
.phase-list li { padding: 0.35rem 0; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
.phase-list li:last-child { border-bottom: none; }
.phase-number { font-weight: 700; color: var(--color-primary); margin-right: 0.5rem; }

/* === Forms === */
.form { max-width: 700px; }

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-bottom: 1rem;
}

.form-group-small { max-width: 120px; flex: 0 0 120px; }

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--color-muted);
    margin-bottom: 0.3rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    height: 36px;
    padding: 0 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--color-surface);
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
/* Reset range and color inputs to native appearance */
input[type="range"],
.form-group input[type="range"] {
    -webkit-appearance: auto;
    -moz-appearance: auto;
    appearance: auto;
    height: auto;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    cursor: pointer;
}
input[type="color"],
.form-group input[type="color"] {
    -webkit-appearance: auto;
    -moz-appearance: auto;
    appearance: auto;
    padding: 2px;
}
.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    padding-right: 2rem;
}
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
}
.form-group textarea {
    height: auto;
    padding: 0.5rem 0.65rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(58,90,64,0.15);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

/* === Placeholder Card (for modules) === */
.placeholder-card {
    background: var(--color-surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 500px;
}
.placeholder-card h2 { margin-bottom: 0.5rem; }
.placeholder-card ul { margin-top: 0.5rem; padding-left: 1.25rem; }
.placeholder-card li { margin-bottom: 0.25rem; font-size: 0.9rem; }

/* === Empty State === */
.empty-state { color: var(--color-muted); font-size: 0.9rem; padding: 1rem 0; }
.empty-state a { color: var(--color-primary); }

/* === Footer === */
.main-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--color-muted);
    font-size: 0.8rem;
}

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

.settings-tab {
    padding: 0.6rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.settings-tab:hover { color: var(--color-text); text-decoration: none; }
.settings-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.settings-panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.settings-section {
    margin-bottom: 1.5rem;
}
.settings-section h2 {
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.inline-form .form-row { margin-bottom: 0; }
.inline-form .form-group { margin-bottom: 0; }

.form-group-btn { flex: 0 0 auto; }

.form-group input[type="color"] {
    -webkit-appearance: color-well;
    appearance: auto;
    width: 60px;
    height: 38px;
    padding: 2px;
    cursor: pointer;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: none;
}
.form-group input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 3px;
}

.color-dot {
    display: inline-block;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    border-radius: 50%;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,0.1);
    overflow: hidden;
    font-size: 0;
    line-height: 0;
}

.actions-cell { white-space: nowrap; text-align: right; }

.row-selected { background: rgba(58,90,64,0.08) !important; }

/* === Responsive === */
@media (max-width: 768px) {
    .detail-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
    .form-group-small { max-width: none; flex: 1; }
    .main-nav { flex-direction: column; height: auto; padding: 0.75rem 1rem; gap: 0.5rem; }
    .nav-links { flex-wrap: wrap; }
    .nav-right { margin-left: 0; }
    .settings-tabs { overflow-x: auto; }
}
