/* ============================================================
   style.css — Quản Lý Toa Chanh
   Main stylesheet: reset, layout, navbar, forms, cards, table
   ============================================================ */

/* ===== CSS Variables (Light Theme) ===== */
:root {
    --green-primary: #2E7D32;
    --green-hover: #1B5E20;
    --green-light: #43A047;
    --green-bg: #E8F5E9;
    --green-border: #A5D6A7;
    --yellow-primary: #F9A825;
    --yellow-bg: #FFFDE7;
    --yellow-border: #FFE082;
    --red-primary: #D32F2F;
    --red-bg: #FFEBEE;
    --red-border: #FFCDD2;

    --bg: #F5F7FA;
    --bg-card: #FFFFFF;
    --bg-input: #FFFFFF;
    --text: #111827;
    --text-muted: #6B7280;
    --text-light: #9CA3AF;
    --border: #E5E7EB;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --radius: 12px;
    --radius-sm: 8px;
    --font-base: 16px;
    /* Reset base font size to standard */
    --navbar-h: 64px;
    --tabbar-h: 60px;
}

/* ===== Utility Classes (New) ===== */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 640px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 768px) {
    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.card-modern {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-modern:hover {
    box-shadow: var(--shadow-md);
}

.input-group-modern {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group-modern input,
.input-group-modern select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: all 0.2s;
    background-color: #FAFAFA;
}

.input-group-modern input:focus,
.input-group-modern select:focus {
    background-color: #fff;
    border-color: var(--green-primary);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
    outline: none;
}

.btn-icon-modern {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--green-bg);
    color: var(--green-primary);
    border: 1px solid var(--green-border);
    transition: all 0.2s;
    margin-left: 8px;
    flex-shrink: 0;
}

.btn-icon-modern:hover {
    background: var(--green-primary);
    color: #fff;
    transform: translateY(-1px);
}


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

html {
    font-size: var(--font-base);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.8rem;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

a:hover {
    text-decoration: underline;
}

img,
svg {
    display: block;
}

button {
    cursor: pointer;
    font-family: inherit;
}

input,
select,
textarea {
    font-family: inherit;
}

/* ===== Layout ===== */
.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content {
    flex: 1;
    padding: 16px;
    padding-top: calc(var(--navbar-h) + 16px);
    padding-bottom: calc(var(--tabbar-h) + 16px);
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ===== Desktop Navbar ===== */
.app-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-h);
    background: var(--green-primary);
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.app-navbar-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 20px;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-brand-icon {
    font-size: 1.4rem;
}

.nav-brand-text {
    display: none;
}

@media (min-width: 600px) {
    .nav-brand-text {
        display: inline;
    }
}

.nav-links {
    display: none;
    gap: 4px;
    flex: 1;
}

@media (min-width: 768px) {
    .nav-links {
        display: flex;
    }
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    text-decoration: none;
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-weight: 700;
}

.nav-link-icon {
    font-size: 1rem;
}

.nav-user-area {
    margin-left: auto;
}

.nav-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 24px;
    padding: 6px 12px 6px 6px;
    color: #fff;
    font-size: 0.8rem;
    transition: background 0.15s;
}

.nav-user-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.nav-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.nav-user-name {
    display: none;
}

@media (min-width: 480px) {
    .nav-user-name {
        display: inline;
    }
}

.nav-user-arrow {
    opacity: 0.7;
}

/* ===== Mobile Tab Bar ===== */
.app-tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tabbar-h);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (min-width: 768px) {
    .app-tabbar {
        display: none;
    }
}

.tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.65rem;
    padding: 6px 0;
    transition: color 0.15s;
    border-top: 2px solid transparent;
}

.tabbar-item.active {
    color: var(--green-primary);
    border-top-color: var(--green-primary);
}

.tabbar-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.tabbar-text {
    font-weight: 500;
}

/* ===== User Dropdown Panel ===== */
.user-dropdown-panel {
    position: fixed;
    top: var(--navbar-h);
    right: 16px;
    width: 280px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 2000;
    display: none;
    overflow: hidden;
}

.user-dropdown-panel.open {
    display: block;
}

.udp-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--green-bg);
    border-bottom: 1px solid var(--green-border);
}

.udp-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--green-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    flex-shrink: 0;
}

.udp-fullname {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
}

.udp-username {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.udp-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.udp-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.font-size-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.font-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.15s;
}

.font-btn:hover,
.font-btn.active {
    background: var(--green-primary);
    border-color: var(--green-primary);
    color: #fff;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 0.85rem;
}

.toggle-switch {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 11px;
    position: relative;
    transition: background 0.2s;
}

[data-theme="dark"] .toggle-switch {
    background: var(--green-primary);
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .toggle-slider {
    transform: translateX(18px);
}

.udp-actions {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.udp-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    text-decoration: none;
    width: 100%;
    text-align: left;
    transition: background 0.15s;
}

.udp-action-btn:hover {
    background: var(--bg);
    text-decoration: none;
}

.udp-action-btn.udp-danger {
    color: #DC2626;
}

.udp-action-btn.udp-danger:hover {
    background: #FEF2F2;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.page-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.date-display {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Form Section ===== */
.form-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}


.form-section h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--green-primary);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-row {
    margin-bottom: 12px;
}

.form-row-split {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.form-inputs {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-result {
    flex-shrink: 0;
    min-width: 120px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.85rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--green-primary);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.12);
}

.form-group input[type="date"] {
    color-scheme: light;
}

.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-btn select {
    flex: 1;
}

.total-display {
    padding: 10px 12px;
    background: var(--green-bg);
    border: 1.5px solid var(--green-border);
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--green-primary);
    text-align: right;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* ===== Batch Sections (Xô / Dạt) ===== */
.batch-section {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    height: 100%;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.batch-section:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.batch-section h4 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.khong-hat-section {
    border-top: 4px solid var(--green-primary);
}

.khong-hat-section h4 {
    color: var(--green-primary);
}

.dat-section {
    border-top: 4px solid var(--yellow-primary);
}

.dat-section h4 {
    color: #F57F17;
    /* Darker yellow for text */
}


.svg-chanh {
    width: 22px;
    height: 22px;
}

/* ===== Batch Summary (form) ===== */
.batch-summary {
    background: linear-gradient(135deg, rgba(46, 125, 50, 0.08), rgba(46, 125, 50, 0.04));
    border: 1.5px solid var(--green-border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 14px;
}

.batch-summary h4 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--green-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.summary-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    padding: 4px 0;
}

.summary-item.khong-hat strong {
    color: #2E7D32;
}

.summary-item.dat strong {
    color: #E65100;
}

.summary-item.total {
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    margin-top: 4px;
}

.summary-item.total strong {
    font-size: 1rem;
    color: var(--green-primary);
}

/* ===== Summary Cards (today stats) ===== */
.summary-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.summary-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
    border-top: 3px solid transparent;
    text-align: center;
}

.summary-card.khong-hat {
    border-top-color: #4CAF50;
}

.summary-card.dat {
    border-top-color: #FDD835;
}

.summary-card.total {
    border-top-color: var(--green-primary);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.card-header h3 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
}

.card-icon {
    display: flex;
    align-items: center;
}

.svg-chanh-lg {
    width: 28px;
    height: 28px;
}

.summary-kg {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.summary-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin: 2px 0;
}

.summary-total {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--green-primary);
}

.summary-total.total-amount {
    font-size: 1rem;
}

/* ===== Transactions Section ===== */
.transactions-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.transactions-section h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===== Transactions Table (Desktop) ===== */
.transactions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    display: none;
}

@media (min-width: 768px) {
    .transactions-table {
        display: table;
    }
}

.transactions-table th {
    background: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 2px solid var(--border);
}

.transactions-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.transactions-table .batch-row:hover {
    background: var(--bg);
}

.transactions-table td.time {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.transactions-table td.kg {
    color: var(--text);
}

.transactions-table td.price {
    color: var(--text-muted);
}

.transactions-table td.khong-hat-price strong {
    color: #2E7D32;
}

.transactions-table td.dat-price strong {
    color: #E65100;
}

.transactions-table td.total strong {
    color: var(--green-primary);
    font-size: 0.9rem;
}

/* ===== Mobile Transaction Cards ===== */
.mobile-transaction-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    overflow: hidden;
    display: block;
}

@media (min-width: 768px) {
    .mobile-transaction-card {
        display: none;
    }
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.mobile-card-seller {
    font-weight: 700;
    font-size: 0.9rem;
}

.mobile-card-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.mobile-card-section {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
}

.mobile-card-section.khong-hat {
    border-left: 3px solid #4CAF50;
}

.mobile-card-section.dat {
    border-left: 3px solid #FDD835;
}

.mobile-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
}

.mobile-card-total {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--green-primary);
}

.mobile-card-actions {
    display: flex;
    gap: 6px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    transition: all 0.15s;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background: var(--green-primary);
    color: #fff;
    width: 100%;
    padding: 14px;
    font-size: 0.9rem;
}

.btn-primary:hover {
    background: var(--green-light);
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.75rem;
}

.btn-print {
    background: var(--green-bg);
    color: var(--green-primary);
    border: 1px solid var(--green-border);
}

.btn-print:hover {
    background: var(--green-border);
}

.btn-delete {
    background: #FEF2F2;
    color: #DC2626;
    border: 1px solid #FECACA;
}

.btn-delete:hover {
    background: #FECACA;
}

.btn-edit {
    background: #E3F2FD;
    color: #1976D2;
    border: 1px solid #BBDEFB;
}

.btn-edit:hover {
    background: #BBDEFB;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--green-primary);
    color: #fff;
    border: none;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.btn-icon:hover {
    background: var(--green-light);
}

/* ===== Icon Text (emoji fallback) ===== */
.icon-text {
    font-style: normal;
}

/* ===== Auth Pages (Login / Register) ===== */
.auth-page {
    background: linear-gradient(135deg, #1B5E20 0%, #2E7D32 50%, #43A047 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 400px;
}

.auth-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-header h1 {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--green-primary);
    line-height: 1.2;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 6px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Alerts ===== */
.alert {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    margin-bottom: 12px;
}

.alert-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

.alert-success {
    background: #F0FDF4;
    color: #166534;
    border: 1px solid #BBF7D0;
}

.alert-icon {
    flex-shrink: 0;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 0.85rem;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .summary-section {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .summary-card {
        padding: 8px 6px;
    }

    .summary-kg {
        font-size: 0.85rem;
    }

    .content {
        padding: 12px;
        padding-top: calc(var(--navbar-h) + 12px);
        padding-bottom: calc(var(--tabbar-h) + 12px);
    }

    .form-row-split {
        flex-direction: column;
    }

    .form-result {
        min-width: unset;
        width: 100%;
    }
}