@font-face {
    font-family: 'Civil Premium';
    src: url('../fonts/Civil Premium Regular.woff2') format('woff2'),
         url('../fonts/Civil Premium Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Civil Premium';
    src: url('../fonts/Civil Premium Medium.woff2') format('woff2'),
         url('../fonts/Civil Premium Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Civil Premium';
    src: url('../fonts/Civil Premium Bold.woff2') format('woff2'),
         url('../fonts/Civil Premium Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --theme-color: #00b199;
    --theme-color-light: #cef9f5;
    --theme-color-mid: #e0f7f4;
    --nav-height: 5rem;
    --content-padding: 4rem;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 8px;
    --color-border: rgba(0,177,153,0.2);
    --color-warning: #f39c12;
    --color-error: #dc3545;
    --color-success: #27ae60;
    --color-bg: #f9f9f6;
    --color-surface: #ffffff;
    --color-text: #00b199;
    --color-text-secondary: #66cdb9;
    --color-input-bg: #ffffff;
    --color-hover-bg: rgba(0,177,153,0.08);
    --color-modal-border: rgba(0,177,153,0.2);
    --color-table-border: rgba(0,177,153,0.12);
    --color-muted: #66cdb9;
    --color-diff-old-bg: #fce4ec;
    --color-diff-new-bg: #e8f5e9;
}

@media screen and (orientation: landscape) { :root { --content-padding: 4rem; } }
@media screen and (orientation: portrait) { :root { --content-padding: 2rem; } }

* {
    margin: 0; padding: 0;
    --foreground-text: var(--color-text);
    --background-color: var(--color-bg);
    font-family: 'Civil Premium', Arial, sans-serif;
    line-height: 1.3;
    box-sizing: border-box;
}

html { font-size: 14px; }
html, body { min-height: 100% !important; height: 100%; width: 100%; overflow: auto; color: var(--foreground-text); }

*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background-color: var(--theme-color); border-radius: 3px; }
* { scrollbar-width: thin; scrollbar-color: var(--theme-color) transparent; }
::selection { background-color: var(--theme-color); color: #fff; }

a { color: var(--theme-color); text-decoration: underline; text-underline-offset: 0.2rem; }

h1 { font-weight: 600; font-size: 1.6rem; margin-top: 0.5rem; }
h2 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; margin-top: 0.5rem; }

/* ── Nav ── */
nav {
    position: absolute; display: block; top: 0; width: 100%;
    height: var(--nav-height); background-color: var(--theme-color);
    box-shadow: var(--shadow-md); z-index: 20;
}

.logo { position: absolute; top: 50%; transform: translateY(-50%); z-index: 10; left: calc(var(--content-padding) + 1rem); display: inline-block; }
.logo-nav { display: block; height: calc(var(--nav-height) - 2rem); }

.nav-home { text-decoration: none; }

.nav-tabs {
    position: absolute; bottom: 0.4rem;
    left: calc(var(--content-padding) + 10rem); right: 16rem;
    display: flex; gap: 0.2rem; align-items: center; justify-content: center;
}

.nav-tab {
    color: white; font-size: 1rem; font-weight: 600; opacity: 0.7;
    text-decoration: none; transition: opacity 0.2s;
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: none; background: none; cursor: pointer;
    border-bottom: 2px solid transparent; padding: 0.35rem 1rem 0.2rem;
}

.nav-tab:hover { opacity: 1; }
.nav-tab.active { opacity: 1; border-bottom-color: white; }

.nav-tab-icon { height: 0.85em; width: auto; color: white; }

.nav-user {
    position: absolute; bottom: 0.4rem; right: var(--content-padding);
    color: white; font-size: 0.9rem; opacity: 0.85;
    display: flex; align-items: center; gap: 0.4rem;
}

.nav-user a { display: flex; align-items: center; }
.nav-role { font-size: 0.75rem; opacity: 0.7; padding: 0.1rem 0.4rem; border: 1px solid rgba(255,255,255,0.4); border-radius: 3px; }
.nav-separator { width: 1px; height: 1rem; background: rgba(255,255,255,0.3); margin: 0 0.2rem; }

.nav-logout-icon { height: 1rem; width: 1rem; color: white; opacity: 0.85; cursor: pointer; transition: opacity 0.2s; }
.nav-logout-icon:hover { opacity: 1; }

.nav-impersonate-icon { height: 1rem; width: 1rem; color: white; opacity: 0.85; cursor: pointer; transition: opacity 0.2s; }
.nav-impersonate-icon:hover { opacity: 1; }

.impersonate-modal {
    position: absolute; top: calc(var(--nav-height) - 0.4rem); right: var(--content-padding);
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 0.5rem;
    padding: 1rem; box-shadow: var(--shadow-lg); z-index: 25; width: 20rem;
}

.impersonate-modal modal-title { display: block; font-size: 1rem; font-weight: 700; margin-bottom: 0.6rem; color: var(--theme-color); }
.impersonate-modal .icon-button { position: absolute; top: 0.5rem; right: 0.5rem; }

/* ── Content ── */
content {
    position: absolute; top: var(--nav-height); display: block;
    left: var(--content-padding); padding: 1rem; padding-bottom: 7rem;
    width: calc(100% - var(--content-padding) * 2);
}

footer { display: block; width: 100%; height: 4rem; background-color: var(--theme-color-light); }
footer version { display: block; text-align: center; padding-top: 1.2rem; font-size: 0.75rem; color: var(--theme-color); opacity: 0.6; }
footer cta { position: fixed; bottom: 1.5rem; right: var(--content-padding); z-index: 15; cursor: pointer; }
footer cta icon { display: flex; align-items: center; justify-content: center; width: 3rem; height: 3rem; background: var(--theme-color); border-radius: 50%; box-shadow: var(--shadow-md); transition: transform 0.15s, box-shadow 0.15s; }
footer cta icon:hover { transform: scale(1.05); box-shadow: var(--shadow-lg); }
footer cta .fab-icon { color: white; width: 1.4rem; height: 1.4rem; }

/* ── Year pills ── */
.year-filter { display: flex; gap: 0.4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.year-pill {
    padding: 0.25rem 0.8rem; border-radius: 1rem; font-size: 0.8rem; font-weight: 600;
    background: var(--theme-color-mid); color: var(--theme-color); cursor: pointer;
    border: none; transition: background 0.15s;
}
.year-pill:hover { background: var(--theme-color-light); }
.year-pill.active { background: var(--theme-color); color: white; }

/* ── Tables ── */
.foi-table { width: 100%; border-collapse: collapse; }
.foi-table th {
    text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em;
    padding: 0.6rem 0.5rem; border-bottom: 2px solid var(--theme-color);
    color: var(--theme-color); opacity: 0.7; text-align: left; white-space: nowrap;
}
.foi-table th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 1.2rem; }
.foi-table th.sortable:hover { opacity: 1; }
.foi-table th.sorted-asc::after { content: '\25B2'; position: absolute; right: 0.2rem; opacity: 0.9; font-size: 0.6rem; }
.foi-table th.sorted-desc::after { content: '\25BC'; position: absolute; right: 0.2rem; opacity: 0.9; font-size: 0.6rem; }

.foi-table th, .foi-table td {
    vertical-align: top; padding: 0.6rem 0.5rem;
    white-space: normal; word-wrap: break-word; overflow: hidden; text-overflow: ellipsis;
}
.foi-table td { border-bottom: 1px solid var(--color-table-border); }
.foi-table tbody tr { cursor: pointer; transition: background 0.1s; }
.foi-table tbody tr:hover { background: var(--color-hover-bg); }

.th-actions { text-align: right; }
.toolbar-actions { display: flex; gap: 0.4rem; justify-content: flex-end; align-items: center; }

.row-count { margin-top: 0.5rem; font-size: 0.75rem; color: var(--color-text-secondary); }

/* ── Filter row ── */
.filter-row td { padding: 0.2rem 0.3rem; border-bottom: 2px solid var(--theme-color-mid); }
.filter-row input {
    width: 100%; padding: 0.25rem 0.4rem; font-size: 0.8rem;
    border: 1px solid var(--color-border); border-radius: 4px;
    font-family: 'Civil Premium', Arial, sans-serif;
}
.filter-row input:focus { outline: none; border-color: var(--theme-color); }
.filter-row.hidden { display: none; }

/* ── Icons ── */
.icon { display: inline-block; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.svg-theme { color: var(--theme-color); }
.svg-red { color: var(--color-error); }
.svg-orange { color: var(--color-warning); }
.svg-green { color: var(--color-success); }
.svg-grey { color: var(--color-muted); }
.svg-white { color: white; }
.clickable { cursor: pointer; transition: opacity 0.15s; }
.clickable:hover { opacity: 0.7; }
.icon-button { width: 1.4rem; height: 1.4rem; cursor: pointer; }
.btn-icon { width: 0.9rem; height: 0.9rem; vertical-align: -0.15em; margin-right: 0.2rem; }

/* ── Modals ── */
.backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.3); z-index: 100; }
.backdrop.hidden { display: none; }

#detail-modal {
    position: fixed; display: block; z-index: 1000;
    left: 15%; width: 70%;
    top: calc(var(--nav-height) + 2rem);
    max-height: calc(100vh - var(--nav-height) - 4rem);
    overflow-y: auto;
}

#edit-form {
    position: fixed; display: block; z-index: 1000;
    left: 20%; width: 60%;
    top: calc(var(--nav-height) + 2rem);
    max-height: calc(100vh - var(--nav-height) - 4rem);
    overflow-y: auto;
}

.detail-container, #inter-form-container {
    background-color: var(--color-surface);
    border: 1px solid var(--color-modal-border);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.detail-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem 1.5rem;
    margin-bottom: 1.5rem;
}

.detail-info-field { display: flex; flex-direction: column; }
.detail-info-field.full-width { grid-column: 1 / -1; }

.detail-info-field label {
    display: block; font-size: 0.85rem; font-weight: 600;
    margin-bottom: 0.3rem; color: var(--theme-color);
}

.detail-info-value {
    background-color: var(--theme-color-light);
    border: 2px solid var(--theme-color);
    border-radius: 0 0 8px 8px;
    min-height: 2.2rem;
    padding: 0.4rem 0.5rem;
    font-size: 0.9rem;
    color: var(--theme-color);
    white-space: pre-line;
    word-break: break-word;
}

.detail-section-title {
    font-size: 0.95rem; font-weight: 700; color: var(--theme-color);
    margin: 1.5rem 0 0.5rem; padding-bottom: 0.3rem;
    border-bottom: 2px solid var(--theme-color);
}

.detail-history-row {
    display: flex; gap: 0.8rem; padding: 0.4rem;
    border-bottom: 1px solid var(--theme-color-light);
    font-size: 0.85rem; align-items: baseline; cursor: pointer;
}
.detail-history-row:hover { background-color: var(--theme-color-light); }
.detail-history-row:last-child { border-bottom: none; }
.detail-history-action { font-weight: 600; flex-shrink: 0; color: var(--theme-color); }
.detail-history-user { opacity: 0.7; flex-shrink: 0; text-align: right; }
.detail-history-time { opacity: 0.7; flex-shrink: 0; font-size: 0.8rem; text-align: right; }
.history-empty { color: var(--color-muted); font-style: italic; padding: 0.5rem 0; }

.detail-bottom-actions { margin-top: 2.5rem; }

.form-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.form-header h2 { font-size: 1.1rem; color: var(--theme-color); }

.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--color-border); }

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

label.required::after { content: ' *'; color: var(--theme-color); font-weight: 600; }

modal-title { display: block; font-size: 1rem; font-weight: 700; color: var(--theme-color); }

/* ── Mini modal (confirm, history diff) ── */
.mini-modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1100; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.3); }
.mini-modal.hidden { display: none; }
.mini-modal-container { background: var(--color-surface); border: 1px solid var(--color-modal-border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 1.5rem; max-width: 36rem; width: 90vw; max-height: 80vh; overflow-y: auto; }

.history-diff-container { width: 38rem; max-width: 90vw; }
.history-diff-old { background-color: var(--color-diff-old-bg); color: var(--color-error); }
.history-diff-new { background-color: var(--color-diff-new-bg); color: var(--color-success); }
.history-diff-table td:first-child { font-weight: 600; color: var(--theme-color); white-space: nowrap; }

/* ── Buttons ── */
.cta-button {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.4rem; padding: 0.6rem 1.4rem;
    background-color: var(--theme-color); color: #fff;
    border: none; border-radius: 0 0 8px 8px;
    font-size: 0.95rem; font-weight: 600;
    font-family: 'Civil Premium', Arial, sans-serif;
    cursor: pointer; transition: background-color 0.2s, transform 0.15s;
}
.cta-button:hover { background-color: #009e88; transform: translateY(-1px); }
.cta-button:focus-visible { outline: 2px solid var(--theme-color); outline-offset: 2px; }
.cta-button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.cta-button-secondary {
    background-color: var(--color-surface); color: var(--theme-color);
    border: 2px solid var(--theme-color);
}
.cta-button-secondary:hover { background-color: var(--theme-color-light); transform: translateY(-1px); }
.cta-button-danger { background-color: var(--color-error); }
.cta-button-danger:hover { background-color: #c82333; transform: translateY(-1px); }
.cta-button-sm { padding: 0.4rem 1rem; font-size: 0.85rem; height: 2.4rem; box-sizing: border-box; flex-shrink: 0; }

.btn-icon { width: 0.95rem; height: 0.95rem; display: block; transform: translateY(-0.05em); }
.cta-button .btn-icon { color: #fff; }
.cta-button-secondary .btn-icon { color: var(--theme-color); }

/* ── Forms ── */
.form-row { margin-bottom: 1rem; }
.form-row label {
    display: block; font-size: 0.85rem; font-weight: 600;
    margin-bottom: 0.3rem; color: var(--theme-color);
}

.inter-input {
    display: block; width: 100%; height: 2.4rem;
    border: 2px solid var(--theme-color); border-radius: 0 0 8px 8px;
    outline-color: var(--theme-color); padding: 0 0.5rem;
    font-size: 0.9rem; box-sizing: border-box;
    font-family: 'Civil Premium', Arial, sans-serif;
    color: var(--theme-color); background-color: var(--color-surface);
}

.inter-input:focus {
    box-shadow: 0 0 0 3px rgba(0,177,153,0.15);
    border-color: var(--theme-color); outline: none;
}

.inter-input::placeholder { color: var(--theme-color); opacity: 0.55; }

textarea.inter-input { height: auto; min-height: 4rem; resize: vertical; padding: 0.4rem 0.5rem; }

select.inter-input {
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300b199'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.4rem center;
    background-size: 1.2rem; padding-right: 2rem; cursor: pointer;
}

input[type=date].inter-input,
input[type=number].inter-input { width: 100%; padding: 0 0.5rem; box-sizing: border-box; }

input[type=date].inter-input::-webkit-calendar-picker-indicator {
    filter: invert(58%) sepia(85%) saturate(953%) hue-rotate(124deg) brightness(79%) contrast(103%);
}

input[type=number].inter-input { -moz-appearance: textfield; }
input[type=number].inter-input::-webkit-inner-spin-button,
input[type=number].inter-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.form-row-half { display: flex; gap: 1rem; margin-bottom: 1rem; }
.form-row-half > .form-col { flex: 1; display: flex; flex-direction: column; }

/* ── Searchable combo ── */
.combo-wrap { position: relative; }
select.combo-hidden { display: none; }
.combo-clear {
    position: absolute; right: 1.8rem; top: 50%; transform: translateY(-50%);
    color: var(--theme-color); font-size: 1.5rem; font-weight: 300;
    display: none; opacity: 0.5; line-height: 1; z-index: 1; cursor: pointer;
}
.combo-clear:hover { opacity: 1; }
.combo-wrap.has-value .combo-clear { display: block; }
input.combo-input {
    display: block; width: 100%; height: 2.4rem;
    border: 2px solid var(--theme-color); border-radius: 0 0 8px 8px;
    outline-color: var(--theme-color); padding: 0 2rem 0 0.5rem;
    font-size: 0.9rem; font-family: 'Civil Premium', Arial, sans-serif;
    color: var(--theme-color); background-color: var(--color-surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300b199'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.4rem center;
    background-size: 1.2rem; cursor: pointer; box-sizing: border-box;
}
input.combo-input:focus { box-shadow: 0 0 0 3px rgba(0,177,153,0.15); border-color: var(--theme-color); outline: none; }
input.combo-input::placeholder { color: var(--theme-color); opacity: 0.55; }
.combo-list {
    display: none; position: fixed; max-height: 14rem; overflow-y: auto;
    background: var(--color-surface); border: 2px solid var(--theme-color);
    border-top: none; border-radius: 0 0 8px 8px; z-index: 2000;
}
.combo-list.open { display: block; }
.combo-item { padding: 0.4rem 0.5rem; font-size: 0.9rem; color: var(--theme-color); cursor: pointer; }
.combo-item:hover, .combo-item.highlighted { background-color: var(--theme-color-light); }
.combo-item.active { font-weight: 600; background-color: var(--theme-color-light); }

/* ── Detail fields ── */
.detail-field { margin-bottom: 0.6rem; }
.detail-field-label { font-size: 0.75rem; font-weight: 600; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-field-value { font-size: 0.9rem; color: var(--color-text); }
.detail-bottom-actions { position: sticky; bottom: 0; background: var(--color-surface); padding-top: 0.5rem; }

/* ── History diff ── */
.history-diff-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-top: 0.5rem; }
.history-diff-table th { text-align: left; padding: 0.3rem 0.5rem; font-weight: 700; border-bottom: 2px solid var(--theme-color); color: var(--theme-color); }
.history-diff-table td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--color-table-border); }

/* ── Toast ── */
#toast {
    visibility: hidden; min-width: 200px; background: var(--color-surface);
    border: 1px solid var(--color-modal-border); color: var(--theme-color);
    text-align: left; border-radius: var(--radius); padding: 0.8rem 1rem;
    position: fixed; z-index: 200; bottom: 2rem; right: 2rem;
    box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.85rem; cursor: pointer;
}
#toast.show { visibility: visible; animation: toast-fadein 0.3s; }
@keyframes toast-fadein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.d-none { display: none !important; }
.hidden { display: none !important; }

/* ── Progress spinner ── */
.lds-ring { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 48px; height: 48px; z-index: 150; }
.lds-ring.hidden { display: none; }
.lds-ring div {
    box-sizing: border-box; display: block; position: absolute;
    width: 48px; height: 48px; border: 4px solid var(--theme-color);
    border-radius: 50%; animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-color: var(--theme-color) transparent transparent transparent;
}
.lds-ring div:nth-child(1) { animation-delay: -0.45s; }
.lds-ring div:nth-child(2) { animation-delay: -0.3s; }
.lds-ring div:nth-child(3) { animation-delay: -0.15s; }
@keyframes lds-ring { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ── Landing page ── */
.banner { display: block; max-width: 400px; margin-top: 10%; margin-left: auto; margin-right: auto; }

.landing-buttons {
    position: absolute; bottom: 8%; width: 100%;
    display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}

.landing-btn {
    display: inline-flex; align-items: center; gap: 0.6rem;
    padding: 0.7rem 1.6rem; border-radius: 2rem; font-size: 0.95rem;
    font-family: 'Civil Premium', Arial, sans-serif; font-weight: 500;
    text-decoration: none; transition: background-color 0.2s, box-shadow 0.2s, transform 0.15s;
    cursor: pointer; min-width: 260px; justify-content: center;
}
.landing-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.landing-btn-secondary { background-color: white; color: var(--theme-color); border: 1.5px solid var(--theme-color); }
.landing-btn-secondary:hover { background-color: #f0faf8; }
.landing-btn-icon { height: 1.2em; width: auto; }

.landing-footer { position: absolute; bottom: 1rem; right: 1.5rem; font-size: 0.75rem; color: var(--theme-color); opacity: 0.6; }

/* ── Status badges ── */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 1rem; font-size: 0.75rem; font-weight: 600; }
.badge-active { background: #e8f5e9; color: #2e7d32; }
.badge-ended { background: #fce4ec; color: #c62828; }
.badge-expiring { background: #fff3e0; color: #e65100; }

/* ── Print ── */
@media print {
    nav, footer, .backdrop, .lds-ring, #toast, .toolbar-actions, .year-filter, .filter-row, .cta-button { display: none !important; }
    content { position: static; width: 100%; left: 0; padding: 0; }
    .foi-table { font-size: 10pt; }
}
