* { box-sizing: border-box; }

:root {
    --header-bg: #3c5670;
    --header-bg-dark: #192533;
    --header-text: #fff;
    --page-bg: #f8f8f8;
    --card-bg: #fff;
    --soft-bg: #e8edf3;
    --border-hairline: #a5b8ce;
    --saved-accent: #d84315;
    --saved-accent-bg: #fbe9e2;
    --saved-accent-border: #f0c4ac;
}

body {
    font-family: system-ui, sans-serif;
    margin: 0;
    color: #1a1a1a;
    background: var(--page-bg);
}

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-form {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    width: 320px;
}

.auth-form h1 {
    font-size: 1.25rem;
    margin: 0 0 1rem;
}

.auth-form label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.auth-form input {
    display: block;
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.25rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.auth-form button {
    width: 100%;
    padding: 0.6rem;
    background: var(--header-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.auth-form button:hover {
    background: var(--header-bg-dark);
}

.error {
    color: #b00020;
    font-size: 0.85rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.75rem;
    background: var(--header-bg-dark);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.topbar h1 {
    color: #fff;
    font-size: 1.2rem;
    margin: 0;
    letter-spacing: 0.01em;
}

main {
    padding: 1.5rem;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.topbar nav a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: #cfe0f2;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.topbar nav a:hover {
    color: #fff;
}

.topbar nav .inline-form button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    padding: 0.4rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.topbar nav .inline-form button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: #fff;
}

.topbar nav svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.items-table th svg,
.summary-table thead th svg,
.timeline-group-heading svg {
    width: 16px;
    height: 16px;
    vertical-align: -3px;
    margin-right: 0.35rem;
    flex-shrink: 0;
}

.inline-form {
    display: inline;
}

.link-button {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: #fdecea;
    border: 1px solid #f3c6c6;
    color: #b00020;
    cursor: pointer;
    padding: 0.35rem 0.7rem;
    border-radius: 4px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
}

.link-button:hover {
    background: #fbdbd8;
    border-color: #e8a5a5;
}

.row-actions a {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--header-bg);
    color: #fff;
    padding: 0.35rem 0.7rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
}

.row-actions a:hover {
    background: var(--header-bg-dark);
}

.row-actions svg,
.link-button svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.item-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    max-width: 900px;
    margin-bottom: 2rem;
}

.item-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    gap: 0.25rem;
}

.item-form input,
.item-form select {
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font: inherit;
}

.item-form select,
.item-form .entity-input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23666' stroke-width='1.5' fill='none' fill-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.item-form .form-actions {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.item-form button {
    padding: 0.5rem 1.25rem;
    background: var(--header-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.item-form button:hover {
    background: var(--header-bg-dark);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.items-table th,
.items-table td {
    text-align: left;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid #eee;
}

.items-table th {
    background: var(--header-bg);
    color: var(--header-text);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

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

.row-actions > a,
.row-actions > .inline-form {
    margin-left: 0.5rem;
}

.row-actions > a:first-child,
.row-actions > .inline-form:first-child {
    margin-left: 0;
}

ul.error {
    color: #b00020;
    background: #fdecea;
    padding: 0.75rem 1.25rem;
    border-radius: 4px;
    max-width: 900px;
}

.saved-view-page .topbar {
    background: var(--saved-accent);
}

.saved-view-page .topbar nav a {
    color: #ffe3d4;
}

.saved-view-page .topbar nav a:hover {
    color: #fff;
}

.saved-view-banner {
    background: var(--saved-accent-bg);
    border: 1px solid var(--saved-accent-border);
    color: #7a3410;
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
}

.dashboard-section {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.dashboard-section h2 {
    margin-top: 0;
}

.section-intro {
    color: #4a5a68;
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

.settings-form {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-hairline);
    margin-bottom: 0.75rem;
}

.settings-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    gap: 0.25rem;
}

.settings-form input {
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font: inherit;
    width: 140px;
}

.settings-form input.wide-input {
    width: 320px;
}

.settings-form button {
    padding: 0.5rem 1.25rem;
    background: var(--header-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.settings-form button:hover {
    background: var(--header-bg-dark);
}

.explainer {
    font-size: 0.85rem;
}

.explainer summary {
    cursor: pointer;
    font-weight: 600;
}

.explainer ul {
    margin: 0.75rem 0 0.25rem;
    padding-left: 1.25rem;
}

.explainer li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

/* Timeline */

.timeline-group {
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--border-hairline);
    margin-bottom: 2rem;
    overflow: hidden;
}

.timeline-group:last-child {
    margin-bottom: 0;
}

.timeline-group-heading {
    padding: 0.6rem 1rem;
    font-weight: 600;
    background: var(--header-bg);
    color: var(--header-text);
    border-bottom: 1px solid var(--header-bg-dark);
}

.timeline-row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
}

.timeline-row:last-of-type {
    border-bottom: none;
}

.timeline-row-label {
    width: 220px;
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.timeline-track {
    position: relative;
    flex: 1;
    height: 2rem;
    margin-right: 1.5rem;
    overflow: hidden;
}

.timeline-dash {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 9px;
    border-radius: 5px;
    background: #2a5a8c;
    cursor: default;
}

.timeline-fade-bar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 9px;
    border-radius: 5px;
    background: #2a5a8c;
    cursor: default;
}

.timeline-subtotal {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--soft-bg);
    border-top: 1px solid var(--border-hairline);
}

.timeline-axis {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
}

.timeline-axis-track {
    height: 1.25rem;
    margin-right: 1.5rem;
}

.timeline-tick {
    position: absolute;
    top: 0;
    left: 0;
    font-size: 0.75rem;
    color: #3a3a3a;
    border-left: 1px solid #ccc;
    padding-left: 4px;
    height: 100%;
    white-space: nowrap;
}

.timeline-gridline {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    border-left: 1px solid #eee;
}

.timeline-row-total {
    width: 130px;
    flex-shrink: 0;
    text-align: right;
    padding: 0.5rem 1rem 0.5rem 0;
    font-size: 0.8rem;
    color: #444;
}

/* Summary table */

.summary-table-wrapper {
    border-radius: 8px;
    border: 1px solid var(--border-hairline);
    overflow-x: auto;
    max-height: 480px;
    overflow-y: auto;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    white-space: nowrap;
}

.summary-table th,
.summary-table td {
    text-align: right;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
}

.summary-table th:first-child,
.summary-table td:first-child {
    text-align: left;
}

.summary-table thead th {
    position: sticky;
    top: 0;
    background: var(--header-bg);
    color: var(--header-text);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
    z-index: 1;
}

.summary-budget-row {
    font-weight: 600;
    background: #dbe9f7;
}

.summary-budget-row td {
    position: sticky;
    top: 2.1rem;
    background: #dbe9f7;
    z-index: 1;
}

.summary-budget-row-inflated {
    background: #fbe8c9;
}

.summary-budget-row-inflated td {
    top: 4.1rem;
    background: #fbe8c9;
}
