/* ===================================================
   Peladang Admin — SaaS Platform Admin Stylesheet
   =================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    color: #1e293b;
    background: #f1f5f9;
    line-height: 1.6;
    min-height: 100vh;
}

a { color: #4338ca; text-decoration: none; }
a:hover { color: #3730a3; text-decoration: underline; }

img { max-width: 100%; }

h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: .5rem; }
h2 { font-size: 1.35rem; font-weight: 600; margin-bottom: .5rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: .25rem; }

/* --- Layout: Sidebar + Main --- */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 250px;
    background: #1e1b4b;
    color: #e0e7ff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform .25s ease;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid #312e81;
    letter-spacing: .02em;
}

.sidebar-brand span {
    color: #a5b4fc;
    font-weight: 400;
    font-size: .85rem;
    display: block;
}

.sidebar-nav {
    list-style: none;
    padding: .5rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem 1rem;
    color: #c7d2fe;
    font-size: .9rem;
    transition: background .15s, color .15s;
    text-decoration: none;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: #312e81;
    color: #fff;
    text-decoration: none;
}

.sidebar-nav li a .nav-icon {
    width: 1.4rem;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-nav .nav-section {
    padding: .75rem 1rem .25rem;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #818cf8;
    font-weight: 600;
}

.sidebar-footer {
    padding: .75rem 1rem;
    border-top: 1px solid #312e81;
    font-size: .82rem;
}

.sidebar-footer .admin-name {
    color: #fff;
    font-weight: 600;
}

.sidebar-footer a {
    color: #a5b4fc;
}

.sidebar-footer a:hover {
    color: #fff;
}

/* --- Mobile sidebar toggle --- */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: .75rem;
    left: .75rem;
    z-index: 200;
    background: #4338ca;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: .5rem .7rem;
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 1.5rem 2rem 3rem;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin-bottom: 0;
}

/* --- Cards --- */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: .75rem;
    color: #334155;
}

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

.stat-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.stat-card .stat-label {
    font-size: .78rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.2;
}

.stat-card .stat-sub {
    font-size: .78rem;
    color: #94a3b8;
}

.stat-card.stat-primary { border-left: 4px solid #4338ca; }
.stat-card.stat-success { border-left: 4px solid #16a34a; }
.stat-card.stat-warning { border-left: 4px solid #eab308; }
.stat-card.stat-danger  { border-left: 4px solid #dc2626; }
.stat-card.stat-info    { border-left: 4px solid #0ea5e9; }

/* --- Tables --- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}

table th,
table td {
    padding: .6rem .75rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

table th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

table tbody tr:hover {
    background: #f8fafc;
}

table tbody tr:nth-child(even) {
    background: #fafbfd;
}

table tbody tr:nth-child(even):hover {
    background: #f1f5f9;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    line-height: 1.5;
}

.badge-active,
.badge-paid,
.badge-success  { background: #dcfce7; color: #166534; }
.badge-trial,
.badge-info     { background: #dbeafe; color: #1e40af; }
.badge-suspended,
.badge-warning,
.badge-pending  { background: #fef9c3; color: #854d0e; }
.badge-cancelled,
.badge-danger,
.badge-overdue,
.badge-void     { background: #fee2e2; color: #991b1b; }
.badge-inactive { background: #f1f5f9; color: #475569; }
.badge-draft    { background: #e2e8f0; color: #334155; }
.badge-green    { background: #dcfce7; color: #166534; }
.badge-gray     { background: #f1f5f9; color: #475569; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: .88rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, box-shadow .15s;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: #4338ca;
    color: #fff;
}
.btn-primary:hover {
    background: #3730a3;
    color: #fff;
}

.btn-secondary {
    background: #e2e8f0;
    color: #334155;
}
.btn-secondary:hover {
    background: #cbd5e1;
    color: #1e293b;
}

.btn-success {
    background: #16a34a;
    color: #fff;
}
.btn-success:hover {
    background: #15803d;
    color: #fff;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
}
.btn-danger:hover {
    background: #b91c1c;
    color: #fff;
}

.btn-warning {
    background: #eab308;
    color: #1e293b;
}
.btn-warning:hover {
    background: #ca8a04;
}

.btn-sm {
    padding: .3rem .65rem;
    font-size: .8rem;
}

.btn-xs {
    padding: .2rem .5rem;
    font-size: .72rem;
}

.btn-outline {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #475569;
}
.btn-outline:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.btn-group {
    display: inline-flex;
    gap: .35rem;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .3rem;
    line-height: 1;
}

.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: #4338ca;
    cursor: pointer;
    font-size: inherit;
    text-decoration: underline;
    text-decoration-color: transparent;
}
.btn-link:hover {
    text-decoration-color: currentColor;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: .3rem;
}

.form-control {
    display: block;
    width: 100%;
    padding: .5rem .75rem;
    font-size: .9rem;
    color: #1e293b;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

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

select.form-control {
    appearance: auto;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-inline {
    display: flex;
    gap: .5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-check {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .4rem;
    font-size: .88rem;
}

.form-check input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: #4338ca;
}

.form-hint {
    font-size: .78rem;
    color: #94a3b8;
    margin-top: .2rem;
}

/* --- Alerts / Flash Messages --- */
.alert {
    padding: .75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: .9rem;
    border-left: 4px solid transparent;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border-color: #16a34a;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #dc2626;
}

.alert-info {
    background: #eff6ff;
    color: #1e40af;
    border-color: #3b82f6;
}

.alert-warning {
    background: #fffbeb;
    color: #854d0e;
    border-color: #eab308;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    gap: .25rem;
    list-style: none;
    margin-top: 1rem;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 .5rem;
    border-radius: 6px;
    font-size: .85rem;
    color: #475569;
    text-decoration: none;
    border: 1px solid #e2e8f0;
    transition: background .15s;
}

.pagination a:hover {
    background: #e0e7ff;
    border-color: #c7d2fe;
    color: #3730a3;
    text-decoration: none;
}

.pagination .active span {
    background: #4338ca;
    color: #fff;
    border-color: #4338ca;
}

.pagination .disabled span {
    color: #cbd5e1;
    cursor: default;
}

/* --- Modal (CSS-only via :target) --- */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 300;
    justify-content: center;
    align-items: center;
}

.modal-backdrop:target {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0;
}

.modal-close {
    color: #94a3b8;
    text-decoration: none;
    font-size: 1.4rem;
    line-height: 1;
}

.modal-close:hover { color: #1e293b; text-decoration: none; }

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

/* --- Filters Bar --- */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}

.filters-bar .form-control {
    width: auto;
    min-width: 160px;
}

/* --- Utility --- */
.text-muted { color: #94a3b8; }
.text-sm    { font-size: .82rem; }
.text-right { text-align: right; }
.text-center{ text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.d-flex { display: flex; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}
.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: .5rem;
}

/* --- Login Page --- */
.login-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%);
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
}

.login-card .login-title {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-card .login-title h1 {
    font-size: 1.5rem;
    color: #1e1b4b;
    margin-bottom: .15rem;
}

.login-card .login-title p {
    color: #94a3b8;
    font-size: .88rem;
}

/* --- Section Heading --- */
.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: .75rem;
    padding-bottom: .35rem;
    border-bottom: 2px solid #e0e7ff;
}

/* --- Detail Grid --- */
.detail-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: .35rem .75rem;
    font-size: .9rem;
}

.detail-grid dt {
    color: #64748b;
    font-weight: 600;
}

.detail-grid dd {
    color: #1e293b;
}

/* --- Intelligence Strip (Phase 5) --- */
.intelligence-strip {
    display: flex;
    gap: 2.13rem;
    margin-bottom: 1.07rem;
    font-size: .88rem;
}

.intelligence-strip .strip-item {
    display: flex;
    flex-direction: column;
}

.intelligence-strip .strip-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
}

.intelligence-strip .strip-label {
    font-size: .78rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 3.5rem;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filters-bar .form-control {
        width: 100%;
        min-width: unset;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

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

/* ===================================================
   Agricultural Intelligence — Phase 10 Styles
   =================================================== */

/* Tab Navigation */
.tab-nav { display: flex; gap: 0; border-bottom: 2px solid #e0e7ff; margin-bottom: 1.5rem; }
.tab-nav a { padding: .6rem 1.25rem; font-size: .88rem; font-weight: 500; color: #475569;
             border-bottom: 2px solid transparent; margin-bottom: -2px; text-decoration: none; transition: color .15s; }
.tab-nav a:hover { color: #4338ca; text-decoration: none; }
.tab-nav a.active { color: #4338ca; border-bottom-color: #4338ca; }

/* Date Range Filter Bar */
.date-range-bar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.date-range-bar .btn-group { display: flex; gap: 0; }
.date-range-bar .btn-group a { border-radius: 0; border-right: 1px solid #e0e7ff; }
.date-range-bar .btn-group a:first-child { border-radius: .375rem 0 0 .375rem; }
.date-range-bar .btn-group a:last-child { border-radius: 0 .375rem .375rem 0; border-right: none; }
.date-range-bar .custom-range { display: flex; gap: .5rem; align-items: center; }
.date-range-bar .custom-range input[type="date"] { padding: .35rem .5rem; border: 1px solid #cbd5e1; border-radius: .375rem; font-size: .85rem; }

/* KPI Cards with Trend Arrows */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: #fff; border: 1px solid #e2e8f0; border-radius: .5rem; padding: 1.25rem; }
.kpi-card .kpi-label { font-size: .8rem; color: #64748b; text-transform: uppercase; letter-spacing: .05em; }
.kpi-card .kpi-value { font-size: 1.75rem; font-weight: 700; color: #1e293b; margin: .25rem 0; }
.kpi-card .kpi-trend { font-size: .8rem; font-weight: 600; }
.kpi-card .kpi-trend.up { color: #16a34a; }
.kpi-card .kpi-trend.down { color: #dc2626; }
.kpi-card .kpi-sub { font-size: .75rem; color: #94a3b8; }

/* Chart containers */
.chart-container { background: #fff; border: 1px solid #e2e8f0; border-radius: .5rem; padding: 1.25rem; margin-bottom: 1.5rem; }
.chart-container h3 { margin: 0 0 1rem 0; font-size: 1rem; color: #334155; }
.chart-container canvas { max-height: 350px; }

/* Show data toggle */
.chart-container details { margin-top: .75rem; }
.chart-container details summary { cursor: pointer; list-style: none; color: #4338ca; font-size: .85rem; font-weight: 500; }
.chart-container details summary::-webkit-details-marker { display: none; }
.chart-container details summary::before { content: 'Show data table'; }
.chart-container details[open] summary::before { content: 'Hide data table'; }

/* Tab placeholder */
.tab-placeholder { padding: 3rem; text-align: center; color: #94a3b8; background: #f8fafc; border-radius: .5rem; border: 1px dashed #e2e8f0; }

/* Perennial Intelligence (Phase 21) */
.badge-orange { background: #ffedd5; color: #9a3412; }
.heatmap-cell { text-align: center; font-size: .8rem; font-weight: 600; padding: .5rem .4rem; min-width: 64px; cursor: pointer; transition: opacity .1s; }
.heatmap-cell:hover { opacity: .85; }
.monitoring-pending { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .8rem; font-weight: 600; background: #dbeafe; color: #1e40af; font-style: italic; }

/* Sortable directions list (SOPs) */
.directions-list { list-style: none; padding: 0; margin: 0; }
.directions-list li {
    display: flex; align-items: flex-start; gap: 8px;
    padding: 10px; margin-bottom: 8px;
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px;
}
.directions-list li.dragging { opacity: .45; background: #e0e7ff; }
.drag-handle { cursor: grab; color: #9ca3af; font-size: 18px; user-select: none; -webkit-user-select: none; line-height: 1; padding-top: 4px; }
.drag-handle:active { cursor: grabbing; }
.directions-list textarea { flex: 1; min-height: 44px; resize: vertical; }
