:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

.view {
    min-height: 100vh;
}

.auth-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
}

.auth-container h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 0.5rem;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.auth-form {
    background: var(--surface);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.auth-form h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-primary:disabled {
    background: var(--secondary-color);
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.875rem;
    margin-right: 0.5rem;
}

.btn-edit {
    background: var(--primary-color);
    color: white;
}

.btn-edit:hover {
    background: #1d4ed8;
}

.btn-delete {
    background: var(--danger-color);
    color: white;
}

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

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

.auth-switch {
    text-align: center;
    margin-top: 1rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
}

.navbar {
    background: var(--surface);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-right: 2rem;
}

.navbar-menu {
    display: flex;
    list-style: none;
    gap: 1.5rem;
    flex: 1;
}

.navbar-menu a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.navbar-menu a:hover {
    color: var(--primary-color);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.navbar-user span {
    color: var(--text-secondary);
}

.ledger-dropdown {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s;
}

.ledger-dropdown:hover {
    border-color: var(--primary-color);
}

.ledger-dropdown:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.content-view {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.card h2, .card h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.amount {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filters input,
.filters select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
}

.table tr:hover {
    background: var(--background);
}

.reports-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.report-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 2rem;
}

.report-section {
    margin-bottom: 2rem;
}

.report-section h3 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.report-total {
    font-weight: bold;
    font-size: 1.25rem;
    padding: 0.75rem;
    background: var(--background);
    margin-top: 1rem;
    border-radius: 4px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: var(--surface);
    margin: 5% auto;
    padding: 2rem;
    border-radius: 8px;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.close:hover {
    color: var(--text-primary);
}

.transaction-entry {
    background: var(--background);
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.journal-entries {
    margin-top: 1rem;
}

.journal-entry {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: end;
}

.error {
    background: #fee;
    color: var(--danger-color);
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.success {
    background: #efe;
    color: var(--success-color);
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.wizard-step {
    animation: fadeIn 0.3s;
}

.wizard-step h3 {
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

#preview-container {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
}

#mapping-form {
    background: var(--background);
    padding: 1.5rem;
    border-radius: 4px;
}

#mapping-form h4 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Posting queue styles */
.transaction-row {
    cursor: pointer;
    transition: background-color 0.2s;
}

.transaction-row:hover {
    background-color: var(--background) !important;
}

.transaction-unbalanced {
    background-color: #fef3c7 !important;
}

.transaction-unbalanced:hover {
    background-color: #fde68a !important;
}

.transaction-details {
    background-color: var(--background);
}

.transaction-details td {
    padding: 0 !important;
}

.transaction-details .table {
    margin: 0;
    background: transparent;
}

.transaction-details .table th,
.transaction-details .table td {
    background: transparent;
}

.text-muted {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

:root {
    --bg-secondary: #f1f5f9;
}

/* Edit transaction form */
.journal-entry {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: end;
}

.journal-entry .form-group {
    margin-bottom: 0;
}

.entry-account-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.entry-account-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.account-name-display {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-draft {
    background: #fef3c7;
    color: #92400e;
}

.status-posted {
    background: #d1fae5;
    color: #065f46;
}

.status-reconciled {
    background: #dbeafe;
    color: #1e40af;
}

/* Toast notifications */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s ease;
}

.toast-show {
    opacity: 1;
    transform: translateX(0);
}

.toast-icon {
    font-size: 1.5rem;
    font-weight: bold;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast-success {
    border-left: 4px solid var(--success-color);
}

.toast-success .toast-icon {
    color: var(--success-color);
}

.toast-error {
    border-left: 4px solid var(--danger-color);
}

.toast-error .toast-icon {
    color: var(--danger-color);
}

.toast-info {
    border-left: 4px solid var(--primary-color);
}

.toast-info .toast-icon {
    color: var(--primary-color);
}

/* Receipts grid */
.receipts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.receipt-card {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.receipt-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.receipt-matched {
    border: 2px solid var(--success-color);
}

.receipt-image-container {
    position: relative;
    width: 100%;
    padding-top: 75%; /* 4:3 aspect ratio */
    background: var(--background);
    overflow: hidden;
}

.receipt-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s;
}

.receipt-image:hover {
    transform: scale(1.05);
}

.receipt-info {
    padding: 1rem;
}

.receipt-meta {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.receipt-meta strong {
    font-size: 0.9rem;
    word-break: break-word;
}

.receipt-meta small {
    color: var(--text-secondary);
    white-space: nowrap;
}

.receipt-status {
    background: var(--success-color);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
    margin: 0.5rem 0;
    font-size: 0.875rem;
}

.receipt-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.receipt-actions .btn {
    flex: 1;
    min-width: fit-content;
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Hamburger menu button */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-primary);
}

@media (max-width: 768px) {
    /* Navbar mobile */
    .navbar {
        padding: 1rem !important;
        flex-wrap: wrap !important;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .navbar-brand {
        margin-right: auto !important;
        font-size: 1.25rem !important;
    }

    .mobile-menu-toggle {
        display: block !important;
        order: -1;
        margin-right: 1rem;
    }

    .navbar .navbar-menu {
        display: none !important;
        width: 100% !important;
        flex-direction: column !important;
        gap: 0 !important;
        margin-top: 1rem !important;
        background: var(--background) !important;
        border-radius: 8px !important;
        overflow: hidden !important;
        flex: none !important;
    }

    .navbar .navbar-menu.active {
        display: flex !important;
    }

    .navbar .navbar-menu li {
        border-bottom: 1px solid var(--border-color);
        display: block !important;
    }

    .navbar .navbar-menu li:last-child {
        border-bottom: none;
    }

    .navbar .navbar-menu a {
        display: block !important;
        padding: 1rem !important;
        background: var(--surface) !important;
    }

    .navbar .navbar-menu a:active {
        background: var(--background) !important;
    }

    .navbar-user {
        width: 100%;
        margin-top: 1rem;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 0.5rem;
    }

    .navbar-user select {
        flex: 1 1 100%;
        order: -1;
    }

    .navbar-user #user-name {
        display: none;
    }

    .navbar-user button {
        flex: 1;
    }

    /* Container spacing */
    .container {
        padding: 1rem;
    }

    /* View header */
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .view-header h1 {
        font-size: 1.5rem;
    }

    .view-header button,
    .view-header > div {
        width: 100%;
    }

    /* Cards */
    .card {
        padding: 1rem;
    }

    /* Dashboard grid */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .amount {
        font-size: 1.5rem;
    }

    /* Filters */
    .filters {
        flex-direction: column;
    }

    .filters input,
    .filters select,
    .filters button {
        width: 100%;
    }

    /* Tables - horizontal scroll */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .table {
        min-width: 600px;
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        white-space: nowrap;
    }

    /* Modal */
    .modal-content {
        margin: 0;
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
        padding: 1rem;
    }

    .close {
        right: 0.5rem;
        top: 0.5rem;
        font-size: 1.75rem;
    }

    /* Journal entries */
    .journal-entry {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 1rem;
        background: var(--background);
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    .journal-entry .form-group {
        margin-bottom: 0.5rem;
    }

    .journal-entry button {
        width: 100%;
    }

    /* Report filters */
    .report-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .report-filters input,
    .report-filters button {
        width: 100%;
    }

    .report-filters label {
        margin-top: 0.5rem;
    }

    /* Reports tabs */
    .reports-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem 1rem;
    }

    .tab-btn {
        white-space: nowrap;
        padding: 0.75rem 1rem;
    }

    /* Receipts grid */
    .receipts-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Toast container */
    #toast-container {
        left: 1rem;
        right: 1rem;
        max-width: calc(100% - 2rem);
    }

    .toast {
        font-size: 0.875rem;
        padding: 0.75rem;
    }

    /* Auth container */
    .auth-container {
        padding: 1rem;
    }

    .auth-container h1 {
        font-size: 2rem;
    }

    .auth-form {
        padding: 1.5rem;
    }

    /* Buttons */
    .btn {
        font-size: 1rem;
        padding: 0.75rem 1rem;
        touch-action: manipulation;
    }

    .btn-sm {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }

    /* Form inputs - larger for touch */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }

    /* Status badges */
    .status-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    /* Transaction entry */
    .transaction-entry {
        padding: 0.75rem;
    }

    /* Wizard steps */
    .wizard-step {
        padding: 0;
    }

    #preview-container {
        max-height: 200px;
    }

    #mapping-form {
        padding: 1rem;
    }
}

/* Small phones */
@media (max-width: 375px) {
    .navbar-brand {
        font-size: 1.1rem;
    }

    .view-header h1 {
        font-size: 1.25rem;
    }

    .card h2 {
        font-size: 1.25rem;
    }

    .amount {
        font-size: 1.25rem;
    }

    .table {
        font-size: 0.8rem;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        position: relative;
    }

    .container {
        padding: 0.75rem;
    }
}

/* iOS safe area support */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .navbar {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
            padding-top: max(1rem, env(safe-area-inset-top));
        }

        .container {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }

        .modal-content {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }
    }
}
