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

:root {
    --primary: #217346;
    --primary-dark: #185a36;
    --primary-light: #4ca777;
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #f57f17;
    --bg: #ebeef2;
    --card-bg: #ffffff;
    --text: #1e1e1e;
    --text-muted: #555;
    --border: #b0b8c4;
    --border-light: #d0d4da;
    --radius: 0px;
    --shadow: none;
    --ribbon-bg: #f3f5f8;
    --ribbon-tabs-bg: #1e6b3f;
    --row-alt: #f2f7f3;
    --row-hover: #d6ecdd;
    --frozen-bg: #e2ebe5;
    --header-bg: #d6dce4;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    font-size: 13px;
}

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

h1 { font-size: 18px; margin-bottom: 12px; }
h2 { font-size: 15px; margin-top: 20px; margin-bottom: 10px; }
h3 { font-size: 14px; margin-bottom: 6px; }

/* === Navbar (Title Bar) === */
.navbar {
    background: var(--primary);
    color: #ffffff;
    padding: 0 16px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--primary-dark);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand a {
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: 0.5px;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 14px;
}

.navbar-menu a {
    color: #d9ecdf;
    font-size: 12px;
    text-decoration: none;
}
.navbar-menu a:hover { color: #ffffff; text-decoration: none; }

.navbar-user { color: #b6d9c1; font-size: 11px; }
.btn-logout { color: #ffcdd2 !important; }

/* === Container === */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* === Workspace (full-width for project detail) === */
.workspace {
    padding: 0;
    margin: 0;
    height: calc(100vh - 36px - 70px - 24px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* === Ribbon === */
.ribbon {
    background: var(--ribbon-bg);
    border-bottom: 1px solid var(--border);
    user-select: none;
}

.ribbon-tabs {
    display: flex;
    padding: 0 8px;
    background: var(--ribbon-tabs-bg);
}

.ribbon-tab {
    padding: 5px 18px;
    color: #d9ecdf;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-decoration: none;
    border-bottom: 2px solid transparent;
}
.ribbon-tab:hover { color: #ffffff; text-decoration: none; }
.ribbon-tab.active {
    background: var(--ribbon-bg);
    color: var(--primary-dark);
    border-bottom-color: var(--ribbon-bg);
}

.ribbon-body {
    display: flex;
    align-items: center;
    padding: 5px 12px;
    gap: 20px;
    min-height: 34px;
}

.ribbon-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 20px;
    border-right: 1px solid var(--border-light);
}
.ribbon-group:last-child { border-right: none; }

.ribbon-group-label {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}

.ribbon-btn {
    padding: 3px 10px;
    background: #ffffff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0;
    font-size: 11px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.ribbon-btn:hover { background: var(--row-hover); color: var(--primary-dark); text-decoration: none; }
.ribbon-btn.active { background: var(--primary); color: #fff; border-color: var(--primary-dark); }

.ribbon-select {
    padding: 2px 6px;
    background: #ffffff;
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 11px;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
.ribbon-select option {
    background: #ffffff;
    color: var(--text);
}

/* === Login === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #ebeef2 0%, #d6e4f0 100%);
}

.login-container { width: 100%; max-width: 380px; padding: 20px; }

.login-card {
    background: white;
    border: 1px solid var(--border);
    padding: 36px;
}

.login-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; color: var(--primary); }
.login-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; font-size: 12px; }

/* === Forms === */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 12px; color: var(--text-muted); }
.form-group input {
    width: 100%; padding: 7px 10px;
    border: 1px solid var(--border); font-size: 13px;
}
.form-group input:focus { outline: none; border-color: var(--primary); }

/* === Buttons === */
.btn {
    padding: 5px 12px; border: 1px solid var(--border);
    font-size: 12px; font-weight: 500; cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px; background: #e8ecf0;
}
.btn-primary { background: var(--primary); color: white; border-color: var(--primary-dark); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; justify-content: center; padding: 10px; margin-top: 8px; }

/* === Alerts === */
.alert { padding: 8px 12px; margin-bottom: 12px; font-size: 12px; border: 1px solid; }
.alert-error { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.messages { max-width: 1400px; margin: 8px auto 0; padding: 0 20px; }

/* === Stats Grid === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 20px; }
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border);
    padding: 14px; text-align: center;
}
.stat-number { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat-credit .stat-number { color: var(--success); }
.stat-debit .stat-number { color: var(--danger); }

/* === Project Grid === */
.project-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px; margin-bottom: 20px;
}
.project-card {
    background: var(--card-bg); border: 1px solid var(--border);
    padding: 14px; text-decoration: none; color: var(--text);
    border-left: 3px solid var(--primary);
    transition: background 0.15s;
}
.project-card:hover { background: var(--row-hover); text-decoration: none; }
.project-card-completed { border-left-color: var(--success); }
.project-card h3 { font-size: 14px; margin-bottom: 4px; }
.project-company { color: var(--text-muted); font-size: 12px; }
.project-date { color: var(--text-muted); font-size: 11px; margin-top: 4px; }
.project-card-header { margin-bottom: 4px; }
.page-header { margin-bottom: 16px; }

.card-link { display: block; text-decoration: none; color: var(--text); }
.card-link:hover { text-decoration: none; }
.card-desc { color: var(--text-muted); font-size: 12px; margin: 4px 0; }

/* === Badges === */
.badge { display: inline-block; padding: 2px 8px; font-size: 10px; font-weight: 600; border: 1px solid; }
.badge-active { background: #dbeafe; color: var(--primary); border-color: #93c5fd; }
.badge-completed { background: #dcfce7; color: var(--success); border-color: #86efac; }

/* === Breadcrumb === */
.breadcrumb { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; padding: 6px 12px; background: #f5f7f9; border: 1px solid var(--border-light); }
.breadcrumb a { color: var(--text-muted); }

/* === Tabs (old style, still used on non-project pages) === */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 18px; color: var(--text-muted); font-weight: 500; font-size: 12px; text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === Project Header === */
.project-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }

/* === Table === */
.table-actions { margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }

.table-wrapper {
    overflow: auto; background: var(--card-bg);
    border: 1px solid var(--border); flex: 1;
}

.data-table { width: 100%; border-collapse: collapse; min-width: 800px; }

.data-table th {
    background: var(--header-bg);
    padding: 4px 6px; text-align: left;
    font-weight: 600; font-size: 11px;
    color: #333; border: 1px solid var(--border);
    white-space: nowrap; position: sticky; top: 0; z-index: 2;
}

.data-table td {
    padding: 1px 4px; border: 1px solid var(--border-light);
    vertical-align: middle; height: 26px; font-size: 12px;
}

.data-table tbody tr:nth-child(even) { background: var(--row-alt); }
.data-table tbody tr:hover { background: var(--row-hover); }

.data-table tfoot td {
    padding: 4px 6px; font-weight: 700;
    background: var(--header-bg); border-top: 2px solid var(--border);
}

.data-table .col-num,
.data-table .cell-num {
    width: 36px; min-width: 36px;
    text-align: center; font-weight: 500;
}
.data-table .col-name { min-width: 180px; }
.col-actions { width: 30px; }

/* === Inline Editing (Spreadsheet cell style) === */
.cell-edit {
    width: 100%; padding: 2px 4px; border: none;
    font-size: 12px; background: transparent; height: 22px; line-height: 22px;
    font-family: inherit;
}
.cell-edit:hover { background: rgba(0,0,0,0.03); }
.cell-edit:focus {
    outline: 2px solid var(--primary-light); outline-offset: -2px;
    background: #fff;
}

.cell-number { text-align: right; width: 90px; }

.data-table th.col-volume,
.data-table td.col-volume { width: 66px; min-width: 66px; text-align: center; }

.data-table th.col-estimate,
.data-table td.col-estimate { width: 120px; min-width: 120px; }
.cell-volume {
    width: 100%; padding: 2px 4px; border: none;
    font-size: 11px; background: transparent; height: 22px; line-height: 22px;
    font-family: inherit; text-align: center;
}
.cell-volume:hover { background: rgba(0,0,0,0.03); }
.cell-volume:focus {
    outline: 2px solid var(--primary-light); outline-offset: -2px;
    background: #fff;
}
select.cell-edit { min-width: 150px; cursor: pointer; }

.computed { text-align: right; padding: 2px 6px; font-weight: 500; color: var(--text-muted); font-size: 12px; }
.total-cell { font-weight: 700; color: var(--text); }

/* === Delete button === */
.btn-delete-row {
    background: none; border: none; color: #999;
    font-size: 14px; cursor: pointer; padding: 2px 4px;
}
.btn-delete-row:hover { color: var(--danger); }

/* === Estimate Table Color Sections === */
.estimate-table { min-width: 1600px; }
.estimate-table .header-group th,
.estimate-table .header-sub th { text-align: center; border: 1px solid var(--border); }

.section-plan, th.section-plan { background: #d5f5d5 !important; color: #1a5c1a; }
.section-fact, th.section-fact { background: #fff9c4 !important; color: #7a6c00; }
.section-diff, th.section-diff { background: #ffcdd2 !important; color: #8b1a1a; }
.section-total, th.section-total { background: #e1bee7 !important; color: #4a148c; }

.bg-plan { background: #edf7ed; }
.bg-fact { background: #fffde7; }
.bg-diff { background: #ffeef0; }
.bg-total { background: #f3e5f5; font-weight: 600; }

.th-unit, .th-unit-sub { background: #e8ecf0 !important; text-align: center !important; font-size: 10px; }
.cell-unit { text-align: center; width: 26px; padding: 1px !important; }
.cell-unit input[type="radio"] { margin: 0; cursor: pointer; }

.estimate-table .cell-number { width: 80px; font-size: 11px; }
.estimate-table select.cell-edit { min-width: 140px; font-size: 11px; }

/* === Searchable Select === */
.search-select { position: relative; min-width: 0; width: 100%; }
.search-select-input {
    width: 100%; padding: 2px 4px; border: none;
    font-size: 12px; background: transparent; height: 22px;
    font-family: inherit;
}
.search-select-input:hover { background: rgba(0,0,0,0.03); }
.search-select-input:focus { outline: 2px solid var(--primary-light); outline-offset: -2px; background: #fff; }

.search-select-dropdown {
    display: none; position: fixed; max-height: 220px; width: 260px;
    overflow-y: auto; background: white; border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 9999;
}
.search-select-dropdown.open { display: block; }
.search-select-option { padding: 6px 10px; font-size: 12px; cursor: pointer; }
.search-select-option:hover,
.search-select-option.highlighted { background: var(--row-hover); color: var(--primary-dark); }
.search-select-empty { padding: 6px 10px; font-size: 12px; color: var(--text-muted); font-style: italic; }

/* === Gantt Table === */
.gantt-table { min-width: 1800px; }
.gantt-year-header {
    text-align: center !important; background: #e8d5a0 !important;
    color: #8b6914; font-size: 12px !important; border: 1px solid var(--border);
}
.gantt-month-header {
    text-align: center !important; font-size: 10px !important;
    padding: 3px 1px !important; min-width: 36px; border: 1px solid var(--border);
}
.gantt-cell { padding: 1px !important; cursor: pointer; border: 1px solid var(--border-light); min-width: 36px; }
.gantt-cell:hover { background: var(--row-hover); }
.gantt-block { width: 100%; height: 22px; transition: background 0.15s; }

.gantt-green { background: #4caf50; }
.gantt-light-green { background: #a5d6a7; }
.gantt-red { background: #ef5350; }
.gantt-light-red { background: #ef9a9a; }
.gantt-yellow { background: #ffee58; }
.gantt-redline { background: linear-gradient(135deg, #ef5350 25%, #c62828 50%, #ef5350 75%); }
.gantt-redline-header { text-align: center !important; background: #ffcdd2 !important; color: #c62828; font-size: 10px !important; min-width: 44px; }
.gantt-redline-cell { background: #fff5f5; }

.gantt-legend {
    display: inline-flex; gap: 12px; font-size: 11px; color: var(--text-muted); vertical-align: middle;
}
.gantt-legend-item { display: inline-flex; align-items: center; gap: 3px; }
.gantt-swatch { display: inline-block; width: 12px; height: 12px; }

/* === Material Table === */
.material-table { min-width: 1800px; }
.mat-slot-header { text-align: center !important; font-size: 10px !important; padding: 3px 1px !important; min-width: 42px; border: 1px solid var(--border); }
.mat-slot { padding: 1px !important; border: 1px solid var(--border-light); }
.mat-slot .cell-edit { width: 52px; font-size: 11px; padding: 2px 3px; }
.mat-slot select.cell-edit { width: 56px; min-width: auto; cursor: pointer; }
.mat-slot .cell-edit.slot-name { width: 40px; text-align: center; }

.mat-total-header { background: #c8e6c9 !important; text-align: center !important; color: #2e7d32; min-width: 45px; }
.mat-remain-header { background: #e1bee7 !important; text-align: center !important; color: #6a1b9a; min-width: 45px; }
.mat-total-cell { background: #e8f5e9; font-weight: 700 !important; color: #2e7d32 !important; }
.mat-remain-cell { background: #f3e5f5; font-weight: 700 !important; color: #6a1b9a !important; }

/* === Finance Sub-tabs === */
.finance-subtabs { display: flex; gap: 0; margin-bottom: 12px; }
.finance-subtab {
    display: inline-block; padding: 5px 16px;
    background: #e0e4e8; color: #333; font-weight: 500; font-size: 12px;
    text-decoration: none; border: 1px solid var(--border); border-bottom: none;
}
.finance-subtab:hover { background: #d0d4da; text-decoration: none; color: #333; }
.finance-subtab.active { background: var(--primary); color: #fff; border-color: var(--primary-dark); }

.finance-total-table { min-width: 900px; }
.finance-month-table { min-width: 1100px; }
.finance-month-table .cell-number { width: 65px; font-size: 11px; }
.dc-credit-row { background: #e8f5e9 !important; }
.dc-credit-row td { border-top: 2px solid #4caf50; }
.dc-debit-row { background: #fce4ec !important; }
.dc-debit-row td { border-top: 2px solid #ef5350; }

/* === Status Bar === */
.statusbar {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 24px; background: #f3f5f8; color: var(--text-muted);
    font-size: 11px; display: flex; align-items: center;
    justify-content: space-between; padding: 0 12px;
    z-index: 100; border-top: 1px solid var(--border);
}
.statusbar-save { color: var(--success); }

/* === Empty state === */
.empty-state { text-align: center; color: var(--text-muted); padding: 30px; font-size: 13px; }

/* === Responsive === */
@media (max-width: 768px) {
    .navbar { padding: 0 10px; }
    .navbar-menu { gap: 8px; font-size: 11px; }
    .container { padding: 12px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
    .project-grid { grid-template-columns: 1fr; }
    .ribbon-tabs { overflow-x: auto; }
    .ribbon-tab { padding: 4px 12px; font-size: 11px; }
}
