/* ==========================================================================
   HarvestFlow Admin UI  —  style.css
   Green-brand, sidebar layout, Chart.js-ready
   ========================================================================== */

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #1a3a28;
    background: #f0f7f3;
}
a { color: #1f704c; text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .5em; line-height: 1.25; }
p { margin: 0 0 .75em; }
ul { list-style: none; padding: 0; margin: 0; }

/* ── CSS custom properties ───────────────────────────────────────────────── */
:root {
    --green-900: #0d2b1a;
    --green-800: #14432b;
    --green-700: #1f704c;
    --green-600: #28895f;
    --green-500: #3aab77;
    --green-100: #eaf7f0;
    --green-50:  #f4fbf7;
    --border:    #d4e9db;
    --text:      #1a3a28;
    --muted:     #4f7060;
    --white:     #ffffff;
    --shadow-sm: 0 1px 4px rgba(20,67,43,.08);
    --shadow:    0 4px 16px rgba(20,67,43,.10);
    --shadow-lg: 0 8px 32px rgba(20,67,43,.13);
    --radius:    12px;
    --radius-sm: 8px;
    --sidebar-w: 240px;
}

/* ── App shell (sidebar + main) ──────────────────────────────────────────── */
.admin-app   { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.admin-sidebar {
    width: var(--sidebar-w);
    background: var(--green-800);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 200;
    overflow-y: auto;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.10);
    text-decoration: none;
}
.sidebar-brand img {
    width: 38px; height: 38px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}
.sidebar-brand .sb-title { font-size: .85rem; font-weight: 700; color: #fff; line-height: 1.2; }
.sidebar-brand .sb-sub   { font-size: .72rem; color: rgba(255,255,255,.6); }

.sidebar-nav { flex: 1; padding: 10px 0; }
.sidebar-section-label {
    padding: 14px 18px 4px;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.4);
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: rgba(255,255,255,.78);
    font-size: .88rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
    text-decoration: none;
}
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--green-500); }
.sidebar-link .sl-icon { font-size: 1rem; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-badge {
    margin-left: auto;
    background: #e53935;
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
}

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.10);
    font-size: .8rem;
    color: rgba(255,255,255,.5);
}
.sidebar-footer a { color: rgba(255,255,255,.6); }
.sidebar-footer a:hover { color: #fff; }

/* ── Main content area ───────────────────────────────────────────────────── */
.admin-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}
.topbar-title  { font-weight: 700; font-size: 1rem; color: var(--text); }
.topbar-right  { display: flex; align-items: center; gap: 12px; }
.topbar-user   { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.topbar-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--green-700);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: .78rem;
    flex-shrink: 0;
}
/* hamburger for mobile */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--green-100); }

/* ── Page content wrapper ────────────────────────────────────────────────── */
.admin-content { padding: 24px; flex: 1; }
.page-header   { margin-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 1.45rem; margin: 0; }
.page-subtitle  { color: var(--muted); font-size: .85rem; margin: 2px 0 0; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 22px;
}
.card + .card { margin-top: 20px; }
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 16px;
}
.card-header h2 { font-size: 1rem; margin: 0; }
.card-title { font-size: 1rem; font-weight: 700; margin: 0 0 16px; color: var(--text); }

/* ── KPI grid ────────────────────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.kpi-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    border-left: 4px solid var(--green-500);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kpi-card.red   { border-left-color: #e53935; }
.kpi-card.amber { border-left-color: #f59f00; }
.kpi-card.blue  { border-left-color: #1e88e5; }
.kpi-card.purple{ border-left-color: #8e24aa; }
.kpi-icon  { font-size: 1.4rem; margin-bottom: 4px; }
.kpi-label { font-size: .73rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1; }
.kpi-sub   { font-size: .78rem; color: var(--muted); }
.kpi-trend { font-size: .75rem; font-weight: 600; }
.kpi-trend.up   { color: #2e7d32; }
.kpi-trend.down { color: #c62828; }

/* ── Layout grids ────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr;     gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.grid-60-40 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; }
.grid-full  { grid-column: 1 / -1; }

/* ── Chart containers ────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }
.chart-wrap.short { height: 180px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}
.data-table th {
    background: var(--green-800);
    color: rgba(255,255,255,.9);
    padding: 10px 12px;
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.data-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.data-table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }
.data-table td { padding: 9px 12px; border-bottom: 1px solid #eaf3ee; vertical-align: middle; }
.data-table tbody tr:hover td { background: var(--green-50); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 9px; border-radius: 999px;
    font-size: .72rem; font-weight: 700; white-space: nowrap;
}
.badge-green  { background: #d4edda; color: #155724; }
.badge-amber  { background: #fff3cd; color: #856404; }
.badge-red    { background: #f8d7da; color: #721c24; }
.badge-blue   { background: #cce5ff; color: #004085; }
.badge-gray   { background: #e2e8e4; color: #3a5044; }
.badge-purple { background: #e8d5f5; color: #5c2282; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-size: .85rem; font-weight: 600; cursor: pointer;
    border: none; font-family: inherit; transition: .2s;
    text-decoration: none; white-space: nowrap;
}
.btn-primary   { background: var(--green-700); color: #fff; }
.btn-primary:hover { background: var(--green-600); color: #fff; text-decoration: none; }
.btn-secondary { background: var(--green-100); color: var(--green-700); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }
.btn-danger    { background: #fee2e2; color: #c62828; }
.btn-danger:hover { background: #fecaca; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-lg { padding: 11px 22px; font-size: .95rem; }

/* legacy .button compat */
.button { display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; background: var(--green-700); color: #fff; border-radius: var(--radius-sm); font-weight: 600; font-size: .85rem; text-decoration: none; border: none; cursor: pointer; font-family: inherit; }
.button:hover { background: var(--green-600); text-decoration: none; color: #fff; }
.button.secondary { background: var(--green-100); color: var(--green-700); border: 1px solid var(--border); }
.button.secondary:hover { background: var(--border); }
.button.large { padding: 10px 20px; font-size: .92rem; }
.button.small { padding: 5px 10px; font-size: .78rem; }
.button.danger { background: #fee2e2; color: #c62828; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.form-row.full  { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text); }
.form-input, .form-select, .form-textarea, input, select, textarea {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .88rem;
    font-family: inherit;
    color: var(--text);
    outline: none;
    transition: border-color .2s;
    background: var(--white);
    width: 100%;
    box-sizing: border-box;
}
.form-input:focus, .form-select:focus, .form-textarea:focus,
input:focus, select:focus, textarea:focus {
    border-color: var(--green-700);
    box-shadow: 0 0 0 3px rgba(31,112,76,.12);
}
textarea, .form-textarea { min-height: 88px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1/-1; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .82rem; color: var(--text); }

/* ── Alerts / Messages ───────────────────────────────────────────────────── */
.alert, .msg {
    padding: 11px 15px; border-radius: var(--radius-sm);
    font-size: .88rem; font-weight: 600; margin-bottom: 16px;
}
.alert-success, .msg.success { background: #d4edda; color: #155724; border-left: 4px solid #28a745; }
.alert-danger,  .msg.error   { background: #f8d7da; color: #721c24; border-left: 4px solid #dc3545; }
.alert-warning, .msg.warning { background: #fff3cd; color: #856404; border-left: 4px solid #ffc107; }
.alert-info    { background: #cce5ff; color: #004085; border-left: 4px solid #0d6efd; }
/* legacy */
.alert { background: #e9f8ee; color: #1f704c; border-left: 4px solid var(--green-500); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 16px; }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 8px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: .8rem; color: var(--text);
}
.pagination a:hover  { background: var(--green-100); text-decoration: none; }
.pagination .active  { background: var(--green-700); color: #fff; border-color: var(--green-700); }
.pagination .disabled{ opacity: .4; pointer-events: none; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 14px 18px; background: var(--white);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
}
.filter-bar input, .filter-bar select { max-width: 200px; }

/* ── Status tabs ─────────────────────────────────────────────────────────── */
.status-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.status-tab {
    padding: 8px 16px; font-size: .85rem; font-weight: 600; color: var(--muted);
    border: none; background: none; cursor: pointer; border-bottom: 3px solid transparent;
    margin-bottom: -2px; white-space: nowrap; font-family: inherit; transition: .2s;
    text-decoration: none;
}
.status-tab:hover { color: var(--text); text-decoration: none; }
.status-tab.active { color: var(--green-700); border-bottom-color: var(--green-700); }
.status-tab .tab-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 18px; padding: 0 5px;
    background: var(--green-100); color: var(--green-700);
    border-radius: 999px; font-size: .7rem; margin-left: 5px;
}
.status-tab.active .tab-count { background: var(--green-700); color: #fff; }

/* ── Dashboard quick-links ───────────────────────────────────────────────── */
.quick-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.quick-link {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 18px 12px; border-radius: var(--radius); background: var(--white);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border);
    text-align: center; text-decoration: none; color: var(--text);
    transition: box-shadow .2s, transform .15s;
    font-size: .82rem; font-weight: 600;
}
.quick-link:hover { box-shadow: var(--shadow); transform: translateY(-2px); text-decoration: none; color: var(--green-700); }
.quick-link .ql-icon { font-size: 1.6rem; }
.quick-link .ql-label { line-height: 1.3; }

/* ── Report summary row ──────────────────────────────────────────────────── */
.report-summary { display: flex; gap: 16px; flex-wrap: wrap; padding: 16px 0; }
.rs-item { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }
.rs-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.rs-value { font-size: 1.35rem; font-weight: 800; color: var(--text); }

/* ── Analytics table ─────────────────────────────────────────────────────── */
.analytics-table td:not(:first-child) { text-align: right; }
.analytics-table th:not(:first-child) { text-align: right; }

/* ── Top products rank ───────────────────────────────────────────────────── */
.top-product-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid #eaf3ee; }
.top-product-row:last-child { border-bottom: none; }
.tp-rank  { font-size: 1rem; font-weight: 800; color: var(--green-600); min-width: 24px; }
.tp-thumb { width: 38px; height: 38px; border-radius: 8px; object-fit: contain; background: var(--green-50); flex-shrink: 0; }
.tp-name  { flex: 1; font-size: .85rem; font-weight: 600; color: var(--text); }
.tp-views { font-size: .8rem; color: var(--muted); text-align: right; white-space: nowrap; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page  { display: grid; place-items: center; min-height: 100vh; background: var(--green-50); }
.login-card  { width: min(440px, calc(100% - 32px)); background: var(--white); padding: 32px; border-radius: 18px; box-shadow: var(--shadow-lg); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand img { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; }

/* ── Admin-header (non-sidebar pages compat) ────────────────────────────── */
.admin-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: wrap; align-items: center;
    justify-content: space-between; gap: 14px;
    background: var(--white); box-shadow: var(--shadow-sm);
}
.admin-branding { display: flex; align-items: center; gap: 12px; }
.admin-brand    { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.admin-brand img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.brand-label { display: block; font-size: .9rem; font-weight: 700; }
.admin-brand small { display: block; color: var(--muted); font-size: .75rem; }
.admin-header h1 { margin: 0; font-size: 1.4rem; }
.subtitle { color: var(--muted); font-size: .82rem; margin: 2px 0 0; }
.admin-header nav { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-grid { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(0,.7fr); gap: 22px; padding: 22px; max-width: 1200px; margin: 0 auto; }
.admin-footer { padding: 18px 24px; color: var(--muted); border-top: 1px solid var(--border); text-align: center; font-size: .8rem; }

/* Constrain all direct <main> children of body (pages without sidebar) */
body > main { max-width: 1200px; margin: 0 auto; width: 100%; box-sizing: border-box; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.thumbs img { width: 100px; height: 68px; object-fit: cover; border-radius: 8px; }

/* ── Repeater rows (manage_products) ────────────────────────────────────── */
.repeater { display: flex; flex-direction: column; gap: 8px; }
.repeater-row { display: grid; gap: 8px; align-items: center; background: var(--green-50); border-radius: 10px; padding: 10px 12px; }
.repeater-row.variant-row  { grid-template-columns: 2fr 1fr 1fr 1fr auto; }
.repeater-row.spec-row     { grid-template-columns: 1fr 2fr auto; }
.repeater-row.image-row    { grid-template-columns: 3fr 1fr auto; }
.repeater-row.tech-row     { grid-template-columns: 1fr auto; }
.btn-remove { background: #fee2e2; color: #c62828; border: none; border-radius: 6px; padding: 5px 9px; cursor: pointer; font-weight: 700; font-size: .78rem; }
.btn-add    { background: var(--green-100); color: var(--green-700); border: 1.5px dashed #7dc99e; border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 600; font-size: .83rem; margin-top: 4px; }

/* ── Report components ───────────────────────────────────────────────────── */
.report-shell { padding: 0; display: flex; flex-direction: column; gap: 0; }
.report-filter-card { padding: 14px 18px; }
.report-filter-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.report-filter-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; color: var(--text); }
.report-filter-form input { min-width: 160px; }
.quick-range-links  { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-actions     { display: flex; gap: 8px; flex-wrap: wrap; }
.report-actions     { display: flex; gap: 10px; flex-wrap: wrap; }
.print-btn { border: 0; cursor: pointer; font: inherit; }
.empty-state { color: var(--muted); font-size: .9rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 300px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #e5efe8; font-size: .85rem; }
th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; background: var(--green-50); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    :root { --sidebar-w: 200px; }
}
@media (max-width: 768px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-main { margin-left: 0; }
    .sidebar-toggle { display: flex; }
    .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; display: none; }
    .sidebar-overlay.show { display: block; }
    .grid-2, .grid-3, .grid-4, .grid-60-40 { grid-template-columns: 1fr; }
    .admin-grid { grid-template-columns: 1fr; padding: 16px; }
    .kpi-grid   { grid-template-columns: 1fr 1fr; }
    .admin-content { padding: 16px; }
    .form-row, .form-grid { grid-template-columns: 1fr; }
    .repeater-row.variant-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .admin-topbar { padding: 0 14px; }
    .admin-content { padding: 12px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar input, .filter-bar select { max-width: 100%; }
}
