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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #dff8ef 0%, #b5eed9 100%);
    min-height: 100vh;
    min-height: 100dvh;
    padding: 14px;
    padding-top: max(14px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.section {
    background: white;
    border-radius: 12px;
    padding: 24px 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    padding-top: 24px;
    padding-bottom: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* Loading: big spinner while checking auth / loading entries */
.loading-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    min-height: 60dvh;
    gap: 24px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.loading-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid #e8e8e8;
    border-top-color: #7dd9b3;
    border-radius: 50%;
    animation: loading-spin 0.9s linear infinite;
}

.loading-label {
    color: #666;
    font-size: 16px;
}

@keyframes loading-spin {
    to {
        transform: rotate(360deg);
    }
}

h1 {
    color: #333;
    margin-bottom: 30px;
    font-size: 32px;
}

h2 {
    color: #555;
    margin-bottom: 20px;
    font-size: 24px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-button {
    background: none;
    border: none;
    padding: 14px 16px;
    min-height: 48px;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    -webkit-tap-highlight-color: transparent;
}

.tab-button.active {
    color: #7dd9b3;
    border-bottom-color: #7dd9b3;
}

.tab-button:hover {
    color: #7dd9b3;
}

/* Forms */
.auth-form {
    max-width: 400px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
}

input[type="email"],
input[type="password"],
input[type="number"],
input[type="text"],
input[type="datetime-local"] {
    width: 100%;
    padding: 14px;
    min-height: 48px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
    -webkit-tap-highlight-color: transparent;
}

input:focus {
    outline: none;
    border-color: #7dd9b3;
}

/* Category combobox: dropdown sorted by recently used, type-to-search, create new (+) */
.category-combobox {
    position: relative;
    width: 100%;
}

.category-combobox input {
    width: 100%;
}

.category-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 4px;
    max-height: min(280px, 60vh);
    overflow-y: auto;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 100;
    -webkit-overflow-scrolling: touch;
}

.category-dropdown[hidden] {
    display: none !important;
}

.category-dropdown-empty {
    display: none;
}

.category-option {
    padding: 14px 16px;
    min-height: 48px;
    font-size: 16px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.category-option:hover,
.category-option.highlight {
    background: #e8f8f2;
}

.category-option-new {
    color: #0d7a4a;
    font-weight: 500;
}

.category-option-plus {
    display: inline-block;
    margin-right: 8px;
    font-weight: 700;
    color: #0d7a4a;
}

/* Entry date: "Current Time" checked = use now, unchecked = show picker. Desktop: toggle row + button side by side; mobile: toggle above button */
.add-entry-date-and-submit {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-top: 8px;
}

.add-entry-submit-wrap {
    flex-shrink: 0;
    margin-left: auto; /* desktop: push button to bottom right of form */
}

.entry-date-toggle-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.entry-date-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 15px;
    color: #555;
    -webkit-tap-highlight-color: transparent;
    min-height: 32px;
}

.entry-date-toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #7dd9b3;
}

.entry-date-picker-wrap[hidden] {
    display: none !important;
}

.entry-date-picker-wrap input {
    min-height: 40px;
    padding: 8px 10px;
}

/* Buttons */
.btn {
    padding: 14px 24px;
    min-height: 48px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Loading state: disabled + spinner */
.btn-loading {
    cursor: not-allowed;
    pointer-events: none;
    opacity: 0.85;
}

.btn .btn-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    margin-right: 8px;
    vertical-align: middle;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: loading-spin 0.9s linear infinite;
}

.btn-primary {
    background: linear-gradient(135deg, #dff8ef 0%, #b5eed9 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(125, 217, 179, 0.4);
}

.auth-form .btn-primary {
    background: #fce4b8;
    color: #333;
}

.auth-form .btn-primary:hover {
    box-shadow: 0 5px 15px rgba(247, 215, 148, 0.5);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
    padding: 12px 20px;
    min-height: 44px;
    font-size: 14px;
}

.btn-danger:hover {
    background: #c82333;
}

/* App Header */
.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px 24px;
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(125, 217, 179, 0.35);
}

.app-title {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #2d3a35;
    background: linear-gradient(135deg, #2d3a35 0%, #3d5249 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-user-block {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: nowrap;
    min-width: 0;
    max-width: 33%;
}

.header-user-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 4em;
    flex: 1 1 0;
    overflow: hidden;
}

.btn-logout {
    flex-shrink: 0;
}

.header-greeting,
#user-email.user-email-subtle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-greeting {
    color: #2d3a35;
    font-weight: 600;
    font-size: 1rem;
}

#user-email.user-email-subtle {
    color: #5a6b63;
    font-size: 0.85rem;
    font-weight: 500;
}

.btn-logout {
    padding: 10px 18px;
    min-height: 44px;
    font-size: 0.9rem;
    font-weight: 600;
    background: transparent;
    color: #5a6b63;
    border: 2px solid rgba(125, 217, 179, 0.6);
    border-radius: 8px;
}

.btn-logout:hover {
    background: rgba(125, 217, 179, 0.2);
    border-color: #7dd9b3;
    color: #2d3a35;
}

/* User menu (three dots) */
.header-user-menu-wrap {
    position: relative;
    flex-shrink: 0;
}
.btn-icon.header-user-menu-trigger {
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    font-size: 1.4rem;
    line-height: 1;
    font-weight: 700;
    color: #5a6b63;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
.btn-icon.header-user-menu-trigger:hover {
    background: rgba(125, 217, 179, 0.2);
    color: #2d3a35;
}
.header-user-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 180px;
    padding: 6px 0;
    background: #fff;
    border: 1px solid rgba(125, 217, 179, 0.5);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
}
.header-user-menu-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 0.95rem;
    color: #2d3a35;
    background: none;
    border: none;
    cursor: pointer;
}
.header-user-menu-item:hover {
    background: rgba(125, 217, 179, 0.15);
}

/* Change password page */
.change-password-header {
    flex-wrap: wrap;
    gap: 12px;
}
.change-password-header .btn-back {
    order: -1;
    padding: 8px 14px;
    font-size: 0.9rem;
    background: transparent;
    color: #5a6b63;
    border: 1px solid rgba(125, 217, 179, 0.5);
    border-radius: 8px;
    cursor: pointer;
}
.change-password-header .btn-back:hover {
    background: rgba(125, 217, 179, 0.2);
    color: #2d3a35;
}
.change-password-form-wrap {
    max-width: 400px;
    margin-top: 24px;
}

/* Add Entry Section */
.add-entry-section {
    background: #f8f9fa;
    padding: 16px 10px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.add-entry-section .btn-primary {
    background: #fce4b8;
    color: #333;
}

.add-entry-section .btn-primary:hover {
    box-shadow: 0 5px 15px rgba(247, 215, 148, 0.5);
}

/* Summary */
.summary {
    display: flex;
    gap: 24px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 20px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.summary-label {
    color: #666;
    font-size: 11px;
}

.summary-value {
    color: #333;
    font-size: 15px;
    font-weight: 600;
}

/* Category breakdown bar chart (spending per category for selected month) */
.category-breakdown {
    padding: 10px 14px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 20px;
}

.category-breakdown-title {
    margin: 0 0 8px 0;
    font-size: 1rem;
    font-weight: 600;
    color: #2d3a35;
}

.category-breakdown-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.category-breakdown-empty {
    margin: 0;
    font-size: 0.9rem;
    color: #5a6b63;
}

.category-breakdown-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(80px, 2fr) 80px;
    align-items: center;
    gap: 10px 12px;
}

.category-breakdown-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #2d3a35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-breakdown-bar-wrap {
    min-height: 24px;
    background: rgba(125, 217, 179, 0.2);
    border-radius: 6px;
    overflow: hidden;
}

.category-breakdown-bar {
    min-height: 24px;
    border-radius: 6px;
    transition: width 0.2s ease;
}

.category-breakdown-amount {
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
    text-align: right;
}

/* Entries month row: month dropdown + CSV button (above summary) */
.entries-month-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    margin-bottom: 16px;
}

.entries-month-row .entries-month-wrap {
    margin-bottom: 0;
}

.entries-month-wrap {
    margin-bottom: 0;
}

.entries-month-select {
    height: 40px;
    min-height: 40px;
    padding: 8px 28px 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: #333;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.entries-month-select:hover {
    border-color: #ccc;
}

.entries-month-select:focus {
    outline: none;
    border-color: #7dd9b3;
    box-shadow: 0 0 0 3px rgba(125, 217, 179, 0.25);
}

.btn-download-csv {
    flex-shrink: 0;
    padding: 8px 16px;
    height: 40px;
    min-height: 40px;
    font-size: 14px;
    font-weight: 600;
    background: #f0f0f0;
    color: #333;
    border: 2px solid #e0e0e0;
}

.btn-download-csv:hover {
    background: #e8f8f2;
    border-color: #7dd9b3;
    color: #2d3a35;
}

/* Entries filter: search by description */
.entries-filter-wrap {
    margin-bottom: 10px;
}

.entries-search-wrap {
    position: relative;
    display: inline-block;
    max-width: 320px;
    width: 100%;
}

.entries-search-label {
    display: block;
    margin-bottom: 6px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

.entries-search-input {
    width: 100%;
    padding: 8px 34px 8px 36px;
    min-height: 34px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23999' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E") no-repeat 12px 50%;
    background-size: 18px 18px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.entries-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #e0e0e0;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.entries-search-clear-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.entries-search-clear-icon svg {
    width: 12px;
    height: 12px;
}

.entries-search-clear:hover {
    background: #ccc;
    color: #333;
}

.entries-search-clear[hidden] {
    display: none !important;
}

.entries-search-input::placeholder {
    color: #999;
}

.entries-search-input:hover {
    border-color: #ccc;
}

.entries-search-input:focus {
    outline: none;
    border-color: #7dd9b3;
    box-shadow: 0 0 0 3px rgba(125, 217, 179, 0.25);
}

/* Entries List – table on desktop, scrollable cards on small screens */
#entries-list {
    width: 100%;
}

/* ----- Mobile sort (visible only on small screens) ----- */
.entries-sort-mobile {
    display: none;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.entries-sort-mobile-label {
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

.entries-sort-mobile-select {
    flex: 1;
    min-width: 0;
    max-width: 280px;
    padding: 8px 12px;
    min-height: 40px;
    font-size: 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    color: #333;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23555' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.entries-sort-mobile-select:focus {
    outline: none;
    border-color: #7dd9b3;
    box-shadow: 0 0 0 3px rgba(125, 217, 179, 0.25);
}

/* ----- Table (visible on desktop) ----- */
.entries-table-wrap {
    width: 100%;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    background: #fff;
}

.entries-table {
    width: 100%;
    min-width: 36em;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 14px;
}

.entries-table thead {
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
}

.entries-table th {
    padding: 12px 12px;
    text-align: left;
    font-weight: 600;
    color: #555;
    min-width: 0;
}

.entries-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.entries-table th.sortable:hover {
    color: #2d3a35;
    background: #eef5f2;
}

.entries-table th .sort-indicator {
    display: inline-block;
    margin-left: 4px;
    width: 0.6em;
    height: 0.6em;
    vertical-align: middle;
    opacity: 0.5;
}

.entries-table th.sortable:hover .sort-indicator {
    opacity: 0.8;
}

.entries-table th .sort-indicator.sort-asc {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 5px solid currentColor;
    width: 0;
    height: 0;
}

.entries-table th .sort-indicator.sort-desc {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    width: 0;
    height: 0;
}

.entries-table th .sort-indicator.sort-none {
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 4px solid currentColor;
    width: 0;
    height: 0;
    opacity: 0.35;
}

.entries-table td {
    padding: 12px 12px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
    min-width: 0;
}

.entries-table .cell-scroll {
    overflow: hidden;
    min-width: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entries-table .entry-category {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.entries-table tbody tr:hover {
    background: #f8f9fa;
}

.entries-table tbody tr:last-child td {
    border-bottom: none;
}

.entries-table .col-amount { width: 13%; min-width: 7.5em; }
.entries-table .col-category { width: 16%; min-width: 5em; }
.entries-table .col-description { width: 20%; min-width: 3.5em; }
.entries-table .col-date { width: 18%; min-width: 9em; }
.entries-table .col-creator { width: 18%; min-width: 4.5em; }
.entries-table .col-actions { width: 15%; min-width: 5.5em; }

.entries-table .btn-danger {
    padding: 6px 14px;
    min-height: 32px;
    font-size: 13px;
}

.entries-table .col-description { color: #555; font-style: italic; }
.entries-table .col-date, .entries-table .col-creator { color: #666; font-size: 13px; }

/* ----- Cards (hidden on desktop, shown on small screens) ----- */
.entries-list-scroll {
    display: none;
    flex-direction: column;
    gap: 14px;
    padding: 2px;
}

.entry-card {
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    min-width: 0;
}

.entry-card:hover {
    border-color: #ddd;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.entry-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 2px;
    min-width: 0;
}

.entry-card-header .entry-category {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 50%;
}

.entry-card-header .entry-amount {
    font-size: 20px;
    font-weight: 700;
}

.entry-card-description {
    color: #555;
    font-size: 14px;
    margin: 0 0 10px 0;
    line-height: 1.45;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.entry-card-meta-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    overflow: hidden;
}

.entry-card-added-by {
    color: #666;
    font-size: 13px;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-card-date {
    color: #666;
    font-size: 13px;
}

/* Card three-dot menu */
.entry-card-menu {
    position: relative;
}

.entry-card-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #666;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.entry-card-menu-dots {
    display: flex;
    align-items: center;
    justify-content: center;
}

.entry-card-menu-dots svg {
    width: 24px;
    height: 10px;
    flex-shrink: 0;
}

.entry-card-menu-btn:hover {
    background: #f0f0f0;
    color: #333;
}

.entry-card-menu-btn[aria-expanded="true"] {
    background: #e8e8e8;
    color: #333;
}

.entry-card-menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 120px;
    padding: 6px 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

.entry-card-menu-dropdown[hidden] {
    display: none !important;
}

.entry-card-menu-dropdown.is-open {
    display: block !important;
}

.entry-card-menu-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.entry-card-menu-item:hover {
    background: #f5f5f5;
}

.entry-card-menu-item-danger {
    color: #dc3545;
    font-weight: 500;
}

.entry-amount {
    font-size: 14px;
    font-weight: 600;
    color: #28a745;
}

.entry-amount.negative {
    color: #dc3545;
}

.entry-category {
    display: inline-block;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    flex-shrink: 0;
}

/* Error Messages */
.error-message {
    color: #dc3545;
    margin-top: 15px;
    padding: 12px;
    background: #f8d7da;
    border-radius: 8px;
    display: none;
}

.error-message.show {
    display: block;
}

.error-message.success {
    color: #0f5132;
    background: #d1e7dd;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 14px;
    color: #999;
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 10px;
}

/* Responsive: table on desktop, cards on small screens */
@media (max-width: 768px) {
    .entries-sort-mobile {
        display: flex !important;
        width: 100%;
    }

    .entries-sort-mobile-select {
        max-width: none;
        flex: 1;
    }

    .entries-filter-wrap {
        width: 100%;
    }

    .entries-search-wrap {
        max-width: none;
        width: 100%;
    }

    .entries-table-wrap {
        display: none !important;
    }

    .entries-list-scroll {
        display: flex !important;
    }
}

@media (min-width: 769px) {
    .entries-table-wrap {
        display: block;
    }

    .entries-list-scroll {
        display: none !important;
    }
}

/* Mobile-first responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .section {
        padding: 20px 12px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: 20px;
        padding-bottom: 20px;
    }

    h1 {
        font-size: 26px;
        margin-bottom: 24px;
    }

    h2 {
        font-size: 20px;
        margin-bottom: 16px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 24px;
        padding-bottom: 20px;
    }

    .app-header .header-user-block {
        width: 100%;
        max-width: 100%;
        justify-content: space-between;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        min-width: 100%;
    }

    .add-entry-date-and-submit {
        flex-direction: column;
        align-items: stretch;
    }

    .add-entry-submit-wrap {
        margin-left: 0; /* mobile: keep button at bottom, full width */
    }

    .add-entry-submit-wrap .btn {
        width: 100%;
    }

    .add-entry-section {
        padding: 14px 8px;
    }

    .summary {
        flex-direction: row;
        gap: 20px;
        padding: 8px 12px;
        margin-bottom: 8px;
    }

    .summary-value {
        font-size: 14px;
    }

    .category-breakdown {
        padding: 8px 12px;
    }

    .category-breakdown-row {
        grid-template-columns: minmax(0, 1fr) minmax(60px, 1fr) minmax(70px, auto);
    }

    .category-breakdown-amount {
        font-size: 0.85rem;
    }

    .entry-card {
        padding: 12px;
    }

    .entry-card-header .entry-amount {
        font-size: 16px;
    }

    .empty-state {
        padding: 40px 12px;
    }

    .empty-state h3 {
        font-size: 18px;
    }

    .toast-container {
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
        top: max(10px, env(safe-area-inset-top));
    }

    .toast {
        padding: 12px 16px;
        min-height: 44px;
        font-size: 14px;
        width: 100%;
    }

    .tabs {
        margin-bottom: 24px;
    }

    .tab-button {
        flex: 1;
        text-align: center;
    }
}

/* Toast: fixed top, safe-area aware, mobile-friendly */
.toast-container {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    top: max(14px, env(safe-area-inset-top));
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    padding: 14px 20px;
    min-height: 48px;
    font-size: 15px;
    font-weight: 500;
    color: #0f5132;
    background: #d1e7dd;
    border: 1px solid rgba(15, 81, 50, 0.2);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: toast-in 0.25s ease-out;
    -webkit-tap-highlight-color: transparent;
}

.toast.toast-out {
    animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

@media (max-width: 380px) {
    .section {
        padding: 16px 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-top: 16px;
        padding-bottom: 16px;
    }

    h1 {
        font-size: 22px;
    }

    h2 {
        font-size: 18px;
    }

    #user-email,
    #user-email.user-email-subtle {
        font-size: 14px;
        word-break: break-all;
    }

    #user-display-name {
        font-size: 16px;
    }
}
