/* App shell refresh: compact, touch-first, and safe for iPhone viewports. */
:root {
    --primary: #176b57;
    --primary-dark: #0f5545;
    --secondary: #2563eb;
    --success: #16845f;
    --warning: #d97706;
    --danger: #dc3545;
    --info: #2563eb;
    --gradient-primary: #176b57;
    --gradient-success: #16845f;
    --gradient-warning: #d97706;
    --gradient-danger: #dc3545;
    --gradient-info: #2563eb;
    --gradient-dark: #17211f;
    --gray-50: #f7f9f8;
    --gray-100: #eef2f1;
    --gray-200: #dce4e2;
    --gray-300: #c5d0cd;
    --gray-400: #899793;
    --gray-500: #62716d;
    --gray-600: #45534f;
    --gray-700: #303c39;
    --gray-800: #182320;
    --header-height: 62px;
    --radius: 8px;
    --radius-lg: 8px;
    --shadow: 0 1px 3px rgba(18, 35, 31, 0.08);
    --shadow-lg: 0 12px 36px rgba(18, 35, 31, 0.18);
    --mobile-nav-height: 66px;
}

html {
    min-height: 100%;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--gray-50);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
    position: static;
    background: var(--gray-50);
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    letter-spacing: 0;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.28);
    outline-offset: 2px;
}

.layout,
.main-content {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    overflow: visible;
}

.main-content {
    min-width: 0;
}

.content {
    overflow: visible;
    padding: 14px 14px calc(var(--mobile-nav-height) + var(--safe-bottom) + 22px);
    width: 100%;
}

.header {
    position: sticky;
    top: 0;
    min-height: calc(var(--header-height) + var(--safe-top));
    padding: calc(9px + var(--safe-top)) 14px 9px;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: none;
    z-index: 700;
}

.header-left {
    min-width: 0;
}

.header-title {
    min-width: 0;
    color: var(--gray-800);
    font-size: 1.05rem;
}

.menu-toggle,
.btn-icon,
.modal-close {
    min-width: 44px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    border-radius: 8px;
}

.menu-toggle {
    background: var(--gray-100);
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
}

.user-info {
    width: 42px;
    height: 42px;
    padding: 3px;
    border-radius: 50%;
    justify-content: center;
    background: #e3f0ec;
}

.user-avatar {
    background: var(--primary);
}

.sidebar {
    background: #17211f;
    padding-bottom: calc(18px + var(--safe-bottom));
}

.sidebar-header {
    border-color: rgba(255,255,255,.08);
}

.sidebar-logo i,
.nav-item.active {
    background: #2b806a;
}

.nav-item {
    min-height: 46px;
}

.nav-item i {
    font-size: 1rem;
}

.mobile-nav {
    position: fixed;
    z-index: 900;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--mobile-nav-height) + var(--safe-bottom));
    padding: 6px max(8px, var(--safe-right)) var(--safe-bottom) max(8px, var(--safe-left));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid var(--gray-200);
    box-shadow: 0 -4px 18px rgba(18, 35, 31, 0.08);
}

.mobile-nav-item {
    min-width: 0;
    min-height: 54px;
    border: 0;
    background: transparent;
    color: var(--gray-500);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-family: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
}

.mobile-nav-item i {
    font-size: 1.15rem;
}

.mobile-nav-item.active {
    color: var(--primary);
}

.mobile-nav-item.active i {
    width: 34px;
    height: 27px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #e3f0ec;
}

.page-pos .content {
    padding: 0;
    overflow: hidden;
}

.page-pos .mobile-nav {
    display: none;
}

.page-pos .pos-layout {
    height: calc(100dvh - var(--header-height) - var(--safe-top));
}

.page-header {
    align-items: center;
    margin-bottom: 14px;
}

.page-header h1 {
    font-size: 1.12rem;
}

.page-header h1 i {
    color: var(--primary);
    margin-right: 4px;
}

.card,
.stat-card,
.filter-section {
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.card-header {
    background: var(--white);
    min-height: 50px;
}

.stat-card {
    border-left: 0;
    padding: 13px;
    min-width: 0;
}

.stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: #e3f0ec !important;
    color: var(--primary);
}

.stat-card:nth-child(2) .stat-icon {
    background: #feecef !important;
    color: var(--danger);
}

.stat-card:nth-child(3) .stat-icon {
    background: #e7f0ff !important;
    color: var(--info);
}

.stat-card:nth-child(4) .stat-icon {
    background: #fff3dc !important;
    color: var(--warning);
}

.stat-info {
    min-width: 0;
}

.stat-info h3 {
    font-size: 1.08rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.stat-info p {
    margin-top: 3px;
    line-height: 1.3;
}

.btn {
    border-radius: 8px;
    min-height: 44px;
    padding: 10px 15px;
}

.btn-primary { background: var(--primary); }
.btn-success { background: var(--success); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); }
.btn-info { background: var(--info); }
.btn-secondary { background: var(--gray-700); }

.btn-sm {
    min-height: 40px;
    padding: 8px 11px;
}

.form-control {
    border-color: var(--gray-300);
    border-radius: 8px;
    background-color: #fff;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 107, 87, .14);
}

.table th {
    background: #edf3f1;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
}

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

.badge {
    border-radius: 6px;
}

.modal {
    height: 100dvh;
    background: rgba(15, 24, 22, 0.55);
}

.modal-content {
    max-height: calc(100dvh - var(--safe-top) - 10px);
}

.modal-header {
    background: #fff;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 i {
    color: var(--primary);
}

.modal-close {
    background: var(--gray-100);
    color: var(--gray-700);
}

.modal-body {
    max-height: calc(100dvh - 155px - var(--safe-top) - var(--safe-bottom));
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 16px;
}

.dashboard-greeting {
    margin: 2px 0 14px;
}

.dashboard-greeting h2 {
    font-size: 1.35rem;
    line-height: 1.3;
}

.dashboard-greeting p {
    color: var(--gray-500);
    margin-top: 3px;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.quick-action {
    min-width: 0;
    min-height: 92px;
    padding: 10px 5px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    background: #fff;
    color: var(--gray-700);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    font-size: .78rem;
    text-align: center;
}

.quick-action i {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    font-size: 1.15rem;
    background: #e3f0ec;
    color: var(--primary);
}

.quick-action.expense i { background: #feecef; color: var(--danger); }
.quick-action.income i { background: #e7f0ff; color: var(--info); }
.quick-action.stock i { background: #fff3dc; color: var(--warning); }

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 18px 0 10px;
}

.section-heading h2 {
    font-size: 1rem;
}

.finance-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.finance-action {
    min-height: 58px;
    justify-content: flex-start;
    font-size: .95rem;
}

.transaction-list {
    display: flex;
    flex-direction: column;
}

.transaction-item {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 11px;
    align-items: center;
    padding: 13px 0;
    border-bottom: 1px solid var(--gray-100);
}

.transaction-item:last-child {
    border-bottom: 0;
}

.transaction-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #e3f0ec;
    color: var(--success);
}

.transaction-item.expense .transaction-icon {
    background: #feecef;
    color: var(--danger);
}

.transaction-main {
    min-width: 0;
}

.transaction-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transaction-meta {
    margin-top: 3px;
    color: var(--gray-500);
    font-size: .75rem;
}

.transaction-side {
    text-align: right;
}

.transaction-amount {
    font-weight: 700;
    color: var(--success);
    white-space: nowrap;
}

.transaction-item.expense .transaction-amount {
    color: var(--danger);
}

.transaction-tools {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.transaction-tools button,
.transaction-tools a {
    border: 0;
    background: transparent;
    color: var(--gray-500);
    min-width: 30px;
    min-height: 30px;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
}

.mobile-card-table {
    min-width: 0;
}

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    padding: calc(28px + var(--safe-top)) 18px calc(28px + var(--safe-bottom));
    background: #eef3f1;
    align-items: center;
}

.login-card {
    width: min(100%, 420px);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(18, 35, 31, .14);
    padding: 28px 24px;
}

.login-logo i {
    background: var(--primary);
    border-radius: 8px;
}

.login-logo h1 {
    color: var(--gray-800);
}

.login-help {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -2px 0 16px;
    color: var(--gray-500);
    font-size: .78rem;
}

.input-with-action {
    position: relative;
}

.input-with-action .form-control {
    padding-right: 52px;
}

.field-action {
    position: absolute;
    right: 3px;
    top: 3px;
    width: 42px;
    height: 42px;
    border: 0;
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
}

.login-footer {
    font-size: .75rem;
}

.alert {
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: 8px;
    display: flex;
    align-items: flex-start;
    gap: 9px;
}

.alert-warning {
    background: #fff7e8;
    border: 1px solid #f0c36a;
    color: #7a4b00;
}

details.filter-section summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--gray-700);
    min-height: 32px;
    display: flex;
    align-items: center;
    gap: 8px;
}

details.filter-section summary::marker {
    color: var(--primary);
}

@media (max-width: 640px) {
    .content {
        padding-left: 12px;
        padding-right: 12px;
    }

    .page-header {
        flex-wrap: nowrap;
        align-items: center;
    }

    .page-header h1 {
        width: auto;
        min-width: 0;
        flex: 1;
    }

    .page-header .btn {
        width: auto;
        flex: 0 0 auto;
    }

    .page-header .btn .btn-label-optional {
        display: none;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }

    .stat-card {
        display: block;
        padding: 12px;
    }

    .stat-icon {
        margin-bottom: 9px;
    }

    .quick-actions {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 7px;
    }

    .quick-action {
        min-height: 86px;
        font-size: .7rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .filter-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .filter-row .form-group:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .table.mobile-card-table,
    .mobile-card-table tbody,
    .mobile-card-table tr,
    .mobile-card-table td {
        display: block;
        width: 100%;
    }

    .mobile-card-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .mobile-card-table tr {
        padding: 9px 12px;
        margin-bottom: 10px;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        background: #fff;
    }

    .mobile-card-table td {
        min-height: 34px;
        padding: 7px 0;
        border-bottom: 1px solid var(--gray-100);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        text-align: right !important;
    }

    .mobile-card-table td:last-child {
        border-bottom: 0;
    }

    .mobile-card-table td::before {
        content: attr(data-label);
        flex: 0 0 34%;
        color: var(--gray-500);
        font-size: .75rem;
        font-weight: 600;
        text-align: left;
    }

    .mobile-card-table td[colspan]::before,
    .mobile-card-table td:only-child::before {
        display: none;
    }

    .table-responsive {
        overflow: visible;
        margin: 0;
        padding: 0;
    }

    .modal-footer {
        gap: 8px;
    }

    .swal2-popup {
        width: calc(100% - 24px) !important;
    }
}

@media (max-width: 374px) {
    .quick-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .finance-actions,
    .filter-row {
        grid-template-columns: 1fr;
    }

    .filter-row .form-group {
        grid-column: auto !important;
    }
}

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

    .content {
        padding: 22px;
    }

    .header {
        padding-left: 22px;
        padding-right: 22px;
    }

    .user-info {
        width: auto;
        height: auto;
        padding: 4px 10px 4px 4px;
        border-radius: 8px;
    }

    .app-grid {
        gap: 20px;
    }

    .modal-content {
        border-radius: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

@media print {
    .mobile-nav { display: none !important; }
}
