/* ── Google Fonts ────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700&display=swap');

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
    --green:        #46962B;
    --green-dark:   #408928;
    --green-light:  #F6FAF5;
    --lime:         #CBD34B;
    --text:         #404040;
    --text-soft:    #595959;
    --text-muted:   #7a8894;
    --border:       #d4e6cc;
    --border-soft:  #e8f0e4;
    --bg:           #F6FAF5;
    --white:        #ffffff;
    --sidebar-bg:   #2d5a1b;
    --sidebar-dark: #1e3d12;
    --danger:       #b91c1c;
    --danger-bg:    #fff1f1;
    --success-bg:   #f0faf0;
    --radius:       0.75rem;
    --radius-sm:    0.4rem;
    --shadow:       0 4px 20px rgba(70, 150, 43, 0.1);
    --shadow-sm:    0 2px 8px rgba(70, 150, 43, 0.08);
}

/* ── Reset / base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Raleway', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    overflow-x: hidden;
}

h1, h2, h3, h4 {
    font-family: 'Raleway', Arial, sans-serif;
    font-weight: 700;
    margin-top: 0;
    color: var(--text);
}

a {
    color: var(--green);
    text-decoration: none;
}

a:hover { color: var(--green-dark); text-decoration: underline; }

button, input, select, textarea { font: inherit; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
    border: 0;
    background: var(--green);
    color: var(--white);
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: background 0.15s;
}

button:hover { background: var(--green-dark); }

.button--confirm { background: var(--green-dark); }
.button--confirm:hover { background: #2d6019; }

.button--secondary {
    background: #e8f0e4;
    color: var(--text);
    border: 0;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    transition: background 0.15s;
}
.button--secondary:hover { background: var(--border); }

.button--cancel {
    color: var(--text-muted);
    text-decoration: underline;
    font-size: 0.9rem;
}
.button--cancel:hover { color: var(--text); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
}

.layout-centered {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

/* ── Main column ─────────────────────────────────────────────────────────── */
.main-column {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
    height: 56px;
    background: var(--white);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.topbar-left {}
.topbar-right { display: flex; align-items: center; gap: 1rem; }

/* ── User menu ───────────────────────────────────────────────────────────── */
.user-menu { position: relative; }

.user-menu__trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: 1.5px solid var(--border);
    border-radius: 2rem;
    padding: 0.35rem 0.75rem 0.35rem 0.35rem;
    color: var(--text);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: border-color 0.15s, background 0.15s;
}

.user-menu__trigger:hover {
    border-color: var(--green);
    background: var(--green-light);
}

.user-menu__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--green);
    color: var(--white);
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-menu__name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-menu__chevron { color: var(--text-muted); flex-shrink: 0; }

.user-menu__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 220px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    z-index: 200;
    overflow: hidden;
}

.user-menu__header {
    padding: 0.85rem 1rem;
    background: var(--green-light);
    border-bottom: 1px solid var(--border-soft);
}

.user-menu__header strong {
    display: block;
    font-size: 0.875rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu__header small {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.user-menu__items { padding: 0.35rem 0; }

.user-menu__item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    color: var(--text);
    font-weight: 500;
    transition: background 0.1s;
}

.user-menu__item:hover {
    background: var(--green-light);
    color: var(--green-dark);
    text-decoration: none;
}

.user-menu__item svg { flex-shrink: 0; color: var(--text-muted); }

.user-menu__footer {
    border-top: 1px solid var(--border-soft);
    padding: 0.35rem 0;
}

.user-menu__logout {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    background: transparent;
    border: 0;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--danger);
    cursor: pointer;
    border-radius: 0;
    transition: background 0.1s;
    text-align: left;
}

.user-menu__logout:hover { background: var(--danger-bg); }

/* ── Profile page ────────────────────────────────────────────────────────── */
.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--green);
    color: var(--white);
    font-size: 1.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.profile-table { width: 100%; border-collapse: collapse; margin-bottom: 0.5rem; }

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

.profile-table th {
    width: 140px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--green-light);
}

.btn-outline {
    display: inline-block;
    border: 1.5px solid var(--green);
    color: var(--green);
    padding: 0.45rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.btn-outline:hover {
    background: var(--green);
    color: var(--white);
    text-decoration: none;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--sidebar-bg);
    color: var(--white);
    padding: 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    width: 240px;
    min-width: 240px;
    max-width: 240px;
    overflow: hidden;
}

.sidebar h1 {
    margin-top: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--white);
    line-height: 1.3;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar h1 span {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: rgba(255,255,255,0.6);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.15rem;
}

.sidebar nav {
    display: grid;
    gap: 0.25rem;
    margin: 1.25rem 0;
    align-content: start;
}

.sidebar nav a {
    color: rgba(255,255,255,0.8);
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    display: block;
}

.sidebar nav a:hover {
    background: rgba(255,255,255,0.12);
    color: var(--white);
    text-decoration: none;
}

.sidebar form {
    border-top: 1px solid rgba(255,255,255,0.15);
    padding-top: 1rem;
    margin-top: auto;
}

.sidebar button {
    background: rgba(255,255,255,0.12);
    color: var(--white);
    width: 100%;
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
}

.sidebar button:hover { background: rgba(255,255,255,0.2); }

/* ── Content area ────────────────────────────────────────────────────────── */
.content {
    padding: 2rem;
    overflow-x: hidden;
    min-width: 0;
    flex: 1;
}

.content--centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 2rem;
}

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-soft);
}

.panel--narrow {
    max-width: 520px;
    width: 100%;
}

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

.stats-grid .panel {
    margin-bottom: 0;
    border-top: 3px solid var(--green);
    padding: 1.25rem;
}

.stats-grid h2 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stats-grid strong {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--green);
    line-height: 1;
    display: block;
}

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-header h2 { margin-bottom: 0; font-size: 1.1rem; }

.section-header a {
    background: var(--green);
    color: var(--white);
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s;
}

.section-header a:hover {
    background: var(--green-dark);
    text-decoration: none;
    color: var(--white);
}

.actions-inline {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* ── Search form ─────────────────────────────────────────────────────────── */
.search-form {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.search-form input { flex: 1; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-grid p {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.9rem;
}

.form-grid label { font-weight: 600; font-size: 0.9rem; color: var(--text-soft); }

input, select, textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(70, 150, 43, 0.15);
}

.form-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 0.75rem;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }

thead tr { background: var(--green-light); }

th {
    text-align: left;
    padding: 0.7rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

td {
    text-align: left;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text);
    font-size: 0.9rem;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--green-light); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.messages { list-style: none; padding: 0; margin-bottom: 1rem; }

.messages li {
    background: var(--success-bg);
    border: 1px solid var(--border);
    border-left: 4px solid var(--green);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--green-dark);
}

/* ── Error / info ────────────────────────────────────────────────────────── */
.error-list {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

/* ── CSV import table ────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }

.row--create td:first-child::before {
    content: "+ ";
    color: var(--green);
    font-weight: bold;
}

.row--update td:first-child::before {
    content: "~ ";
    color: #a05a00;
    font-weight: bold;
}

.row--create { background: #f0fdf4; }
.row--update { background: #fffbeb; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--border-soft);
    color: var(--text-soft);
    padding: 0.15rem 0.6rem;
    border-radius: 9999px;
    margin-left: 0.4rem;
}

.badge--ok { background: #dcfce7; color: #166534; }
.badge--missing { background: var(--border-soft); color: var(--text-muted); }

/* ── Preview actions ─────────────────────────────────────────────────────── */
.preview-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 1.5rem;
}

/* ── Consent / signature ─────────────────────────────────────────────────── */
.consent-panel { max-width: 680px; }

.consent-body { display: grid; gap: 1.25rem; }

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

.consent-table th,
.consent-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
}

.consent-table th {
    width: 140px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--green-light);
}

.consent-text {
    background: #f0faf0;
    border-left: 4px solid var(--green);
    padding: 0.75rem 1rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.95rem;
    color: var(--green-dark);
}

.signature-label {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
}

.signature-area {
    background: var(--green-light);
    border: 2px solid var(--green);
    border-radius: var(--radius);
    padding: 1.25rem;
    position: relative;
}

.signature-wrapper { position: relative; }

#signature-canvas {
    display: block;
    width: 100%;
    height: 200px;
    box-sizing: border-box;
    border: 3px solid var(--green);
    outline: 4px solid rgba(70, 150, 43, 0.2);
    border-radius: var(--radius-sm);
    background: var(--white);
    cursor: crosshair;
    touch-action: none;
}

#signature-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--border);
    font-size: 1rem;
    pointer-events: none;
    user-select: none;
}

#signature-placeholder svg { opacity: 0.5; }

.signature-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.consent-panel .form-actions {
    gap: 1.5rem;
    margin-top: 1.25rem;
}

.signature-status { font-size: 0.9rem; font-weight: 600; }

.consent-error {
    color: var(--danger);
    background: var(--danger-bg);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    margin: 0;
    border: 1px solid #fecaca;
}

/* ── Back link ───────────────────────────────────────────────────────────── */
.back-link {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.back-link:hover { color: var(--green); text-decoration: none; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-panel {
    width: 100%;
    max-width: 400px;
}

.login-panel h2 {
    color: var(--green-dark);
    margin-bottom: 0.25rem;
}

.login-panel .subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-logo span {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--green);
    letter-spacing: 0.02em;
}

.login-logo small {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 0.1rem;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { width: 100%; min-width: 0; max-width: 100%; padding-bottom: 1rem; }
    .content { padding: 1rem; }
    .section-header, .search-form { flex-direction: column; align-items: stretch; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
