:root {
    --c-primary: #0f766e;
    --c-primary-light: #14b8a6;
    --c-accent: #0ea5e9;
    --c-bg: #f1f5f9;
    --c-surface: #ffffff;
    --c-text: #1e293b;
    --c-text-dim: #64748b;
    --c-border: #e2e8f0;
    --c-danger: #ef4444;
    --c-success: #10b981;
    --c-warning: #f59e0b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* Login */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #0f766e 0%, #0ea5e9 100%);
    padding: 20px;
}
.login-box {
    background: #fff; border-radius: 12px; padding: 36px 28px;
    width: 100%; max-width: 380px; box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.login-box img { display: block; width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 10px; }
.login-box h2 { text-align: center; font-size: 18px; margin-bottom: 24px; color: var(--c-primary); }
.login-box .form-group { margin-bottom: 14px; }
.login-box label { display: block; font-size: 13px; color: var(--c-text-dim); margin-bottom: 4px; }
.login-box input {
    width: 100%; height: 42px; border: 1px solid var(--c-border); border-radius: 8px;
    padding: 0 12px; font-size: 14px; outline: none; transition: border 0.2s;
}
.login-box input:focus { border-color: var(--c-primary); }
.login-box button {
    width: 100%; height: 44px; background: var(--c-primary); color: #fff;
    border: none; border-radius: 8px; font-size: 15px; cursor: pointer; margin-top: 8px;
}
.login-box button:active { opacity: 0.9; }
.login-box .error-msg { color: var(--c-danger); font-size: 13px; text-align: center; margin-top: 12px; display: none; }
.login-box .role-hint { font-size: 12px; color: var(--c-text-dim); text-align: center; margin-top: 16px; line-height: 1.6; }

/* Header */
.app-header {
    background: linear-gradient(135deg, #0f172a, #1e293b);
    color: #fff; padding: 12px 20px;
    display: flex; align-items: center; justify-content: flex-end; gap: 12px;
    position: sticky; top: 0; z-index: 90; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    min-height: 60px;
}
.app-header .header-center {
    display: flex; align-items: center; gap: 14px;
    position: absolute; left: 50%; transform: translateX(-50%);
}
.app-header img { width: 40px; height: 40px; border-radius: 8px; }
.app-header h1 { font-size: 20px; font-weight: 700; white-space: nowrap; }
.app-header .header-right { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #94a3b8; }
.app-header .user-info { color: #e2e8f0; }
.app-header .logout-btn { padding: 4px 10px; background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.2); border-radius: 4px; cursor: pointer; font-size: 12px; }

/* Tab Bar */
.tab-bar {
    display: flex; justify-content: center; overflow-x: auto;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border); position: sticky; top: 60px; z-index: 80;
    scrollbar-width: none; gap: 2px; padding: 0 8px;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-bar button {
    flex-shrink: 0; padding: 10px 14px; border: none; background: none;
    font-size: 13px; color: var(--c-text-dim); cursor: pointer;
    border-bottom: 2px solid transparent; transition: all 0.2s;
    border-radius: 6px 6px 0 0;
}
.tab-bar button:hover { color: var(--c-primary); background: #f0fdfa; }
.tab-bar button.active {
    color: var(--c-primary); border-bottom-color: var(--c-primary);
    font-weight: 600; background: #f0fdfa;
}

/* Main Content */
.main-content { padding: 16px; max-width: 1400px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Toolbar */
.toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--c-border);
}
.toolbar .spacer { flex: 1; }
.count-info { font-size: 12px; color: var(--c-text-dim); }

/* Buttons */
.btn {
    padding: 7px 14px; border: 1px solid var(--c-border); border-radius: 6px;
    background: var(--c-surface); font-size: 13px; cursor: pointer;
    transition: all 0.2s; white-space: nowrap;
}
.btn:hover { border-color: var(--c-primary); color: var(--c-primary); }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-light); color: #fff; }
.btn-danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Table */
.data-table-wrap { overflow-x: auto; background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: #f8fafc; }
th { padding: 10px 12px; text-align: left; font-weight: 600; color: var(--c-text-dim); border-bottom: 2px solid var(--c-border); white-space: nowrap; }
td { padding: 8px 12px; border-bottom: 1px solid #f1f5f9; }
tr:hover td { background: #f8fafc; }

/* Status badges */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500;
}
.badge-growing { background: #dbeafe; color: #1d4ed8; }
.badge-withdrawal { background: #fef3c7; color: #b45309; }
.badge-ready { background: #d1fae5; color: #065f46; }
.badge-harvested { background: #f3e8ff; color: #6b21a8; }
.badge-settled { background: #fce7f3; color: #9d174d; }

/* Modal */
.modal-overlay {
    display: none; position: fixed; top:0; left:0; right:0; bottom:0;
    background: rgba(0,0,0,0.5); z-index: 200;
    align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: var(--c-surface); border-radius: 12px; width: 100%; max-width: 640px;
    max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); padding: 24px;
}
.modal-box h3 { margin-bottom: 16px; font-size: 17px; }
.modal-box .form-group { margin-bottom: 12px; }
.modal-box label { display: block; font-size: 13px; color: var(--c-text-dim); margin-bottom: 4px; }
.modal-box label .required { color: var(--c-danger); }
.modal-box input, .modal-box select, .modal-box textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px;
    font-size: 14px; font-family: inherit; outline: none;
}
.modal-box input:focus, .modal-box select:focus, .modal-box textarea:focus { border-color: var(--c-primary); }
.modal-box textarea { min-height: 80px; resize: vertical; }
.modal-box .btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-box .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Dashboard */
.dash-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.dash-card { background: var(--c-surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.dash-card .card-value { font-size: 28px; font-weight: 700; color: var(--c-primary); }
.dash-card .card-label { font-size: 12px; color: var(--c-text-dim); margin-top: 4px; }

.dash-section { margin-bottom: 20px; }
.dash-section h3 { font-size: 15px; margin-bottom: 10px; color: var(--c-text); }

/* Map */
.map-container {
    background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; min-height: 420px; position: relative;
}
.map-flag {
    position: absolute; cursor: pointer; transform: translate(-50%, -100%);
    transition: transform 0.2s; z-index: 10;
}
.map-flag:hover { transform: translate(-50%, -100%) scale(1.3); z-index: 20; }
.flag-pole {
    width: 2px; height: 18px; background: #666; margin: 0 auto;
}
.flag-banner {
    background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff;
    padding: 3px 6px; border-radius: 3px; font-size: 10px; font-weight: 700;
    white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    text-align: center;
}

/* QR Code */
.qr-preview { text-align: center; padding: 20px; }
.qr-preview img { max-width: 250px; border: 1px solid var(--c-border); border-radius: 8px; }
.qr-preview .qr-url { font-size: 12px; color: var(--c-text-dim); margin-top: 10px; word-break: break-all; }

/* Forecast bar */
.forecast-bar { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.forecast-day {
    flex: 1; min-width: 60px; background: var(--c-surface); border-radius: 6px;
    padding: 8px; text-align: center; box-shadow: var(--shadow); font-size: 12px;
}
.forecast-day .day-num { font-size: 20px; font-weight: 700; color: var(--c-primary); }
.forecast-day .day-label { color: var(--c-text-dim); font-size: 11px; }

/* Summary row */
.summary-row td { background: #f0fdf4 !important; font-weight: 700; border-top: 2px solid #10b981; }
.summary-row .num { color: #065f46; font-size: 14px; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--c-text-dim); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* Alert for overdue */
.alert-item {
    padding: 10px 14px; border-left: 3px solid var(--c-warning); background: #fffbeb;
    margin-bottom: 8px; border-radius: 0 6px 6px 0; font-size: 13px;
}

/* Sync options list */
.sync-list { max-height: 240px; overflow-y: auto; }
.sync-group-title {
    font-size: 12px; color: var(--c-text-dim); padding: 8px 0 4px;
    border-bottom: 1px solid var(--c-border); margin-bottom: 4px;
}
.sync-group-title:first-child { padding-top: 0; }
.sync-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 0; cursor: pointer; border-bottom: 1px solid #f8fafc;
    font-size: 13px;
}
.sync-row:active { background: #f8fafc; }
.sync-row input[type="checkbox"] {
    width: 16px; height: 16px; flex-shrink: 0; margin-left: 8px; accent-color: var(--c-primary);
}
.sync-text {
    flex: 1; min-width: 0; color: var(--c-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sync-text i { font-style: normal; color: var(--c-primary); font-size: 11px; }
.sync-same-seed .sync-text { font-weight: 600; }

/* Clickable table rows */
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #e0f2fe !important; }

/* Batch history modal */
.bh-header {
    display: flex; flex-wrap: wrap; gap: 14px; padding: 12px 16px;
    background: #f0fdfa; border-radius: 8px; margin-bottom: 16px;
    font-size: 13px; border: 1px solid #ccfbf1;
}
.bh-header span { white-space: nowrap; }
.bh-stats {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px;
}
.bh-stat {
    background: var(--c-surface); border-radius: 8px; padding: 12px; text-align: center;
    box-shadow: var(--shadow); border-left: 3px solid var(--c-primary);
}
.bh-stat-val { font-size: 22px; font-weight: 700; color: var(--c-primary); }
.bh-stat-label { font-size: 11px; color: var(--c-text-dim); margin-top: 2px; }
@media (max-width: 768px) { .bh-stats { grid-template-columns: 1fr 1fr; } }

/* Print-only (hidden on screen) */
.print-only { display: none; }

/* Print styles */
@media print {
    .app-header, .tab-bar, .toolbar, .btn, .modal-overlay, .logout-btn { display: none !important; }
    body { background: #fff; }
    .main-content { padding: 0; max-width: 100%; }
    .data-table-wrap { box-shadow: none; border: 1px solid #000; }
    table { font-size: 11px; }
    th, td { border: 1px solid #000; padding: 4px 6px; }
    .print-only { display: block !important; }
    .dash-cards { display: none; }
    .dash-section { page-break-inside: avoid; }
}

/* Mobile */
@media (max-width: 768px) {
    .app-header { min-height: 50px; padding: 8px 12px; }
    .app-header .header-center { position: static; transform: none; flex: 1; }
    .app-header h1 { font-size: 14px; }
    .app-header img { width: 28px; height: 28px; }
    .tab-bar { top: 50px; }
    .tab-bar { justify-content: flex-start; }
    .tab-bar button { padding: 8px 10px; font-size: 12px; }
    .main-content { padding: 10px; }
    .dash-cards { grid-template-columns: 1fr 1fr; }
    .dash-card .card-value { font-size: 22px; }
    .modal-box { max-width: 100%; padding: 16px; }
    .modal-box .form-row { grid-template-columns: 1fr; }
    table { font-size: 12px; }
    th, td { padding: 6px 8px; }
}
