/* =============================================================================
   AgroTrack — Stil aplicatie
   ============================================================================= */

:root {
    --primary: #2d5016;
    --primary-dark: #1f3a0e;
    --primary-light: #4a7c2a;
    --accent: #c97b3c;
    --accent-soft: #f4e3cf;

    --bg: #f8f7f2;
    --surface: #ffffff;
    --surface-alt: #f1efea;
    --border: #e0ddd4;
    --border-strong: #cbc7bb;

    --text: #1f1d18;
    --text-muted: #6b6759;
    --text-subtle: #94907f;

    --success: #2d7d32;
    --success-bg: #e8f5e9;
    --warning: #b85c00;
    --warning-bg: #fff4e6;
    --danger: #c62828;
    --danger-bg: #fdecea;

    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 2px 8px rgba(31, 29, 24, .08);
    --shadow-lg: 0 8px 24px rgba(31, 29, 24, .12);

    --font-display: 'Lora', Georgia, serif;
    --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --header-h: 60px;
    --sidebar-w: 240px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    color: var(--text);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    color: var(--text);
    font-weight: 600;
    line-height: 1.2;
    margin: 0 0 12px 0;
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; font-family: var(--font-body); font-weight: 600; }

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

/* =============================================================================
   Layout principal cu sidebar
   ============================================================================= */

.app-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas:
        "sidebar header"
        "sidebar main";
}

.app-header {
    grid-area: header;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 10;
}

.app-header__title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 500;
    color: var(--text-muted);
}

.app-header__user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.app-header__user-name {
    color: var(--text);
    font-weight: 500;
}

.app-header__user-rol {
    color: var(--text-subtle);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.app-sidebar {
    grid-area: sidebar;
    background: var(--primary-dark);
    color: #f0ecdc;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.app-sidebar__brand {
    padding: 18px 20px;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 600;
    color: #f0ecdc;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-sidebar__brand-icon {
    font-size: 24px;
}

.app-sidebar__nav {
    padding: 12px 0;
    flex: 1;
}

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #d8d3bf;
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.app-sidebar__link:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
    text-decoration: none;
}

.app-sidebar__link--active {
    background: rgba(255,255,255,.12);
    color: #fff;
    border-left-color: var(--accent);
    font-weight: 500;
}

.app-sidebar__link-icon {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.app-sidebar__footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
    font-size: 12px;
    color: rgba(216, 211, 191, .6);
}

.app-main {
    grid-area: main;
    overflow-y: auto;
    padding: 28px 32px;
    max-width: 100%;
}

.app-main__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.app-main__title-group { display: flex; flex-direction: column; gap: 4px; }
.app-main__subtitle { color: var(--text-muted); font-size: 14px; }

/* =============================================================================
   Butoane
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn--primary:hover:not(:disabled) {
    background: var(--primary-dark);
    text-decoration: none;
}

.btn--ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border-strong);
}
.btn--ghost:hover:not(:disabled) {
    background: var(--surface-alt);
    text-decoration: none;
}

.btn--danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn--danger:hover:not(:disabled) {
    background: #a02020;
    text-decoration: none;
}

.btn--sm {
    padding: 5px 10px;
    font-size: 13px;
}

.btn--icon {
    padding: 6px 8px;
}

/* =============================================================================
   Cards
   ============================================================================= */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.card--clickable {
    cursor: pointer;
    transition: all 0.15s;
}
.card--clickable:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

/* KPI cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
}

.kpi__label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin-bottom: 4px;
}

.kpi__value {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
}

.kpi__unit {
    font-size: 14px;
    color: var(--text-muted);
    margin-left: 4px;
    font-family: var(--font-body);
    font-weight: normal;
}

.kpi--accent { border-top: 3px solid var(--primary); }

/* =============================================================================
   Forms
   ============================================================================= */

.form-group {
    margin-bottom: 16px;
}

.form-group--row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-label__required {
    color: var(--danger);
    margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: all 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45, 80, 22, 0.12);
}

.form-input--error {
    border-color: var(--danger);
}

.form-error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
}

.form-help {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

/* =============================================================================
   Tabele
   ============================================================================= */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    overflow-y: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th {
    background: var(--surface-alt);
    text-align: left;
    padding: 10px 16px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr.row-inactive {
    opacity: 0.55;
}

.table__actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* =============================================================================
   Badge / Pills
   ============================================================================= */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.badge--success { background: var(--success-bg); color: var(--success); }
.badge--warning { background: var(--warning-bg); color: var(--warning); }
.badge--danger  { background: var(--danger-bg); color: var(--danger); }
.badge--muted   { background: var(--surface-alt); color: var(--text-muted); }

/* =============================================================================
   Modal
   ============================================================================= */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 29, 24, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 20px 20px;
    z-index: 100;
    animation: fadeIn 0.15s ease-out;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideDown 0.2s ease-out;
}

.modal--sm { max-width: 400px; }
.modal--lg { max-width: 800px; }
.modal--xl { max-width: 1100px; }

.modal__header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal__title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.modal__close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}
.modal__close:hover { color: var(--text); }

.modal__body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal__footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    background: var(--surface-alt);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   Toast notifications
   ============================================================================= */

.toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
}

.toast {
    background: var(--text);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    min-width: 240px;
    max-width: 360px;
    animation: slideInRight 0.2s ease-out;
    border-left: 3px solid var(--primary-light);
}

.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* =============================================================================
   Empty state
   ============================================================================= */

.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty__icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.empty__title {
    font-family: var(--font-display);
    font-size: 20px;
    color: var(--text);
    margin-bottom: 8px;
}

.empty__desc {
    font-size: 14px;
    margin-bottom: 16px;
}

/* =============================================================================
   Search bar
   ============================================================================= */

.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 20px;
}

.search-bar__input {
    flex: 1;
    max-width: 360px;
}

/* =============================================================================
   Login page (separat de layout-ul aplicatiei)
   ============================================================================= */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(circle at 20% 30%, rgba(74, 124, 42, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(201, 123, 60, 0.05) 0%, transparent 50%),
        var(--bg);
}

.login-card {
    background: var(--surface);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
}

.login-card__brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-card__brand-icon { font-size: 32px; margin-bottom: 4px; }

.login-card__brand-name {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
    color: var(--primary);
}

.login-card__brand-tagline {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 2px;
}

/* =============================================================================
   Loading / Spinner
   ============================================================================= */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner--dark {
    border-color: rgba(0,0,0,.15);
    border-top-color: var(--primary);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-wrap {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* =============================================================================
   Utility
   ============================================================================= */

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 8px !important; }
.mt-2 { margin-top: 16px !important; }
.mt-3 { margin-top: 24px !important; }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }

.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* Mobile responsive */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }
    .app-sidebar { display: none; }
    .form-group--row { grid-template-columns: 1fr; }
}
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    margin-bottom: -1px;
}

.tab:hover {
    color: var(--text);
    background: var(--surface-alt);
}

.tab--active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab__icon {
    font-size: 16px;
}
/* Container harta */
.harta-container {
    width: 100%;
    height: calc(100vh - 280px);
    min-height: 500px;
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
}

/* Toolbar deasupra hartii */
.harta-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    margin-top: 8px;
}

.harta-toolbar__group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.harta-toolbar__divider {
    width: 1px;
    height: 28px;
    background: var(--border);
}

/* Info line (sub toolbar) — mesaje contextuale */
.harta-info-line {
    min-height: 32px;
    padding: 6px 12px;
    background: #fff8e6;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    font-size: 13px;
    color: #6b5800;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.harta-info-line:empty {
    display: none;
}

/* Stats sub harta */
.harta-stats {
    padding: 8px 12px;
    text-align: right;
}

/* Butoane color-coding */
.color-btn {
    background: transparent;
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.color-btn:hover {
    background: var(--surface-alt);
}

.color-btn--active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Legenda */
.harta-legenda {
    background: white;
    padding: 10px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    max-width: 260px;
    font-size: 12px;
}

.harta-legenda__title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.harta-legenda__total {
    color: var(--text-muted);
    font-size: 11px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.harta-legenda__items {
    max-height: 280px;
    overflow-y: auto;
}

.harta-legenda__item {
    display: grid;
    grid-template-columns: 16px 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 3px 0;
    font-size: 12px;
}

.harta-legenda__swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
}

.harta-legenda__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.harta-legenda__ha {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.harta-legenda__count {
    color: var(--text-muted);
    font-size: 11px;
    background: var(--surface-alt);
    padding: 1px 6px;
    border-radius: 100px;
    min-width: 20px;
    text-align: center;
}

/* Popup-uri Leaflet — butoane in popup */
.leaflet-popup-content {
    margin: 12px !important;
}

.popup-btn {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

.popup-btn:hover {
    background: var(--surface);
    border-color: var(--primary);
}

/* Sub-controls Leaflet — adaptare la stilul aplicatiei */
.leaflet-control-attribution {
    font-size: 10px !important;
}

/* Responsive */
@media (max-width: 768px) {
    .harta-container {
        height: calc(100vh - 240px);
        min-height: 400px;
    }
    .harta-toolbar {
        gap: 6px;
    }
    .harta-toolbar__divider {
        display: none;
    }
    .harta-legenda {
        max-width: 200px;
        font-size: 11px;
    }
}


/* =============================================================================
   AgroTrack — Fix z-index pentru modal peste harta Leaflet
   =============================================================================
   Leaflet foloseste z-index ~400-1000 pentru tile-urile si controlele sale.
   Modalele noastre folosesc z-index implicit (sau prea mic) si ajung sub harta.
   Acest patch forteaza modalele si toast-urile sa fie deasupra.

   Adauga acest cod la sfarsitul fisierului existent css/app.css
   ============================================================================= */

/* Modal backdrop (overlay-ul intunecat) */
.modal-backdrop {
    z-index: 10000 !important;
}

/* Modal-ul propriu-zis */
.modal {
    z-index: 10001 !important;
}

/* Toast-uri (notificari) trebuie sa fie deasupra modalelor */
.toast-container,
.toasts,
.toast {
    z-index: 10002 !important;
}

/* Fix pentru continutul Leaflet — il tinem sub modal */
.leaflet-pane,
.leaflet-top,
.leaflet-bottom {
    z-index: 400 !important;
}

.leaflet-control-container {
    z-index: 500 !important;
}

/* Cand harta e in fullscreen sau modal e deschis */
body.modal-open .leaflet-container {
    pointer-events: none;
}
body.modal-open .modal,
body.modal-open .modal-backdrop {
    pointer-events: auto;
}

/* =============================================================================
   AgroTrack — Fix pentru aliniere coloane cu actiuni in tabele
   =============================================================================
   Problema: in pagina Parcele si Sezoane, linia orizontala dintre randuri
   se opreste la coloana de actiuni iar butoanele apar ca "rupte" de restul
   randului.
   
   Cauza: .table__actions are display:flex aplicat pe <td>, ceea ce face ca
   celula sa iasa din table-row layout si sa piarda border-bottom-ul.
   
   Fix: redefinim .table__actions ca tabel-cell normal, iar butoanele 
   sunt aliniate cu alta tehnica (inline-block + text-align right).
   
   Adauga acest CSS la SFARSITUL fisierului existent css/app.css
   (overrides regulile precedente cu specificitate egala dar ordine ulterioara)
   ============================================================================= */

.table__actions {
    /* OVERRIDE display:flex de mai sus din app.css */
    display: table-cell !important;
    text-align: right;
    white-space: nowrap;
}

.table__actions .btn {
    margin-left: 4px;
    vertical-align: middle;
}

.table__actions .btn:first-child {
    margin-left: 0;
}

/* Pentru containere de spans (badges) in interiorul .table__actions */
.table__actions span,
.table__actions .text-sm,
.table__actions .text-muted {
    vertical-align: middle;
}