:root {
    --bg-color: #0d1117;
    --bg-gradient: linear-gradient(135deg, #091c1d, #1a3c40, #255855);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --accent-color: #48CAE4;
    --accent-hover: #00B4D8;
    --primary-color: #10B981; 
    --primary-hover: #059669;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --success-color: #10B981;
    --border-radius: 16px;
    --sidebar-width: 260px;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: var(--glass-shadow);
}

.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    margin: 16px;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.logo-container {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--glass-border);
}

.logo-icon {
    font-size: 24px;
    color: var(--primary-color);
    filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.5));
}

.logo-container h2 {
    font-size: 20px;
    font-weight: 700;
}

.logo-container span {
    color: var(--primary-color);
    font-weight: 300;
}

.main-nav {
    flex: 1;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 10px;
    transition: var(--transition);
    font-weight: 500;
}

.nav-item:hover, .nav-item.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--primary-color);
}

.nav-item i {
    font-size: 18px;
    width: 20px;
    text-align: center;
}

.nav-item.active {
    border-right: 4px solid var(--primary-color);
    background: linear-gradient(90deg, transparent, rgba(16, 185, 129, 0.15));
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--glass-border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.details .name {
    display: block;
    font-size: 14px;
    font-weight: 600;
}

.details .role {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 16px 16px 0;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-left: 16px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    width: 400px;
    border-radius: 30px;
}

.search-bar input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    width: 100%;
    font-size: 14px;
}

.search-bar input::placeholder {
    color: var(--text-secondary);
}

.topbar-actions {
    display: flex;
    gap: 12px;
}

.btn-icon {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

/* Content Area View Logic */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 0 16px;
}

.content-area::-webkit-scrollbar {
    width: 6px;
}
.content-area::-webkit-scrollbar-thumb {
    background: var(--glass-bg);
    border-radius: 10px;
}
.content-area::-webkit-scrollbar-thumb:hover {
    background: var(--glass-border);
}

.view-section {
    display: none;
    animation: fadeIn 0.4s ease-in-out;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.header-action {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
}

.header-action h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Buttons */
button {
    font-family: 'Inter', sans-serif;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

.btn-link:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

.btn-action {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    margin-right: 4px;
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-edit:hover { color: var(--warning-color); border-color: var(--warning-color); }
.btn-delete:hover { color: var(--danger-color); border-color: var(--danger-color); }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: rgba(72, 202, 228, 0.1);
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-icon.stats-green { background: rgba(16, 185, 129, 0.1); color: var(--success-color); }
.stat-icon.stats-orange { background: rgba(245, 158, 11, 0.1); color: var(--warning-color); }
.stat-icon.stats-purple { background: rgba(168, 85, 247, 0.1); color: #A855F7; }

.stat-info h3 {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
}

/* Panels */
.panels-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.panel {
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.full-height-panel {
    min-height: 500px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.panel-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.panel-tools {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 8px;
    width: 300px;
}

.search-box input {
    background: transparent;
    border: none;
    color: white;
    outline: none;
    width: 100%;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.custom-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.custom-table th, .custom-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.custom-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.custom-table tbody tr {
    transition: var(--transition);
}

.custom-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05); /* very slightly lighter hover */
}

/* Badges for tags, codes etc */
.badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: none;
    align-items: flex-start; /* Aling to top to allow scrolling */
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow-y: auto; /* Allow overlay to scroll */
    padding: 40px 20px;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal {
    width: 100%;
    max-width: 500px;
    padding: 0;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin: auto; /* Center in scrollable overlay */
    max-height: none; /* Let content be as tall as needed, overlay will scroll */
}

/* Specific wider modal for terrains */
.modal-lg {
    max-width: 900px;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

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

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--danger-color);
}

.modal-body {
    padding: 24px;
}

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

.form-row {
    display: flex;
    gap: 16px;
}

.form-group.half {
    width: 50%;
}

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

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    outline: none;
    transition: var(--transition);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

textarea {
    resize: vertical;
}

select option {
    background: #111827; /* Solid color for select dropdown options in dark mode */
    color: white;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Map Placeholder */
.map-container {
    height: calc(100vh - 200px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-placeholder {
    text-align: center;
    color: var(--text-secondary);
    max-width: 400px;
}

.map-icon-large {
    font-size: 64px;
    margin-bottom: 20px;
    color: rgba(255,255,255,0.05);
}

/* Print Styles for Certificate */
.print-only {
    display: none;
}

@media print {
    body {
        background: none !important;
        color: black !important;
    }
    body * {
        visibility: hidden;
    }
    #printable-certificate, #printable-certificate *, #printable-receipt, #printable-receipt * {
        visibility: visible;
    }
    #printable-certificate, #printable-receipt {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 40px;
        background: white !important;
        color: black !important;
        display: block !important;
    }
    
    .certificate-container {
        border: 4px double #000;
        padding: 60px 40px;
        text-align: left;
        font-family: 'Times New Roman', Times, serif;
    }
    .cert-header {
        text-align: center;
        margin-bottom: 40px;
        border-bottom: 2px solid #000;
        padding-bottom: 20px;
    }
    .cert-header h2 { font-size: 16px; color: #333; margin-bottom: 5px; }
    .cert-header h1 { font-size: 26px; margin-top: 15px; font-weight: bold; }
    
    .cert-body { font-size: 18px; line-height: 1.6; text-align: justify; }
    .cert-details { margin: 30px 0; padding: 25px; border: 1px solid #aaa; background: white !important; }
    .d-row { margin-bottom: 12px; display: flex; }
    .d-row strong { width: 300px; display: inline-block; }
    
    .validity-warn {
        font-weight: bold;
        text-align: center;
        margin: 40px 0;
        padding: 15px;
        border: 2px dashed #000;
        font-size: 16px;
        text-transform: uppercase;
    }
    
    .cert-dates {
        display: flex;
        justify-content: space-between;
        margin-bottom: 100px;
        margin-top: 40px;
    }
    
    .cert-signatures {
        display: flex;
        justify-content: space-around;
        margin-top: 50px;
    }
    .signature-line {
        border-top: 1px solid #000;
        width: 300px;
        text-align: center;
        padding-top: 10px;
        font-weight: bold;
    }
}
