/* Htay Business - Modern UI Components */
:root {
    --brand: #991b1b;
    --brand-dark: #5c1018;
    --brand-light: #fef2f2;
    --page-bg: #f3f4f6;
    --input-bg: #f0f4f8;
}

body { font-family: Inter, system-ui, sans-serif; }

.btn,
.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    min-width: fit-content;
    width: auto;
    max-width: none;
    flex-shrink: 0;
    padding: 0.625rem 1.25rem;
    border-radius: 0.75rem;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25rem;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(153, 27, 27, 0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #b91c1c 0%, #7f1d1d 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(153, 27, 27, 0.28);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #991b1b 0%, #5c1018 100%);
    box-shadow: 0 6px 18px rgba(153, 27, 27, 0.34);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(153, 27, 27, 0.24);
}

.btn-secondary {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    color: #111827;
}

.btn-secondary:active {
    background: #f3f4f6;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.22);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm,
.btn-primary.btn-sm,
.btn-secondary.btn-sm,
.btn-danger.btn-sm {
    min-height: 2.25rem;
    padding: 0.4375rem 0.875rem;
    font-size: 0.8125rem;
    border-radius: 0.625rem;
}

.btn[disabled],
.btn-primary[disabled],
.btn-secondary[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.form-input {
    width: 100%; border-radius: 0.875rem; border: 1px solid #e5e7eb;
    background: var(--input-bg); padding: 0.75rem 1rem; font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-input:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(153, 27, 27, 0.12);
}
.form-label { display: block; margin-bottom: 0.375rem; font-size: 0.875rem; font-weight: 500; color: #374151; }

.card {
    border-radius: 1rem; border: 1px solid #eef0f3; background: #fff;
    padding: 1.25rem; box-shadow: var(--card-shadow, 0 1px 3px rgba(15,23,42,.06));
}
.kpi-card {
    border-radius: 1rem; border: 1px solid #eef0f3; background: #fff;
    padding: 1.25rem 1.5rem; box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.kpi-card .kpi-label { font-size: 0.8125rem; font-weight: 500; color: #6b7280; }
.kpi-card .kpi-value { margin-top: 0.375rem; font-size: 1.75rem; font-weight: 700; color: #111827; line-height: 1.2; }
.kpi-card .kpi-sub { margin-top: 0.25rem; font-size: 0.75rem; color: #9ca3af; }

.badge {
    display: inline-flex; align-items: center; border-radius: 9999px;
    padding: 0.2rem 0.65rem; font-size: 0.75rem; font-weight: 600;
}
.badge-active { background: #fff7ed; color: #c2410c; }
.badge-success { background: #ecfdf5; color: #047857; }
.badge-danger { background: #fef2f2; color: #b91c1c; }
.badge-brand { background: #fef2f2; color: #991b1b; }

.table-wrap {
    overflow-x: auto; border-radius: 1rem; border: 1px solid #eef0f3;
    background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.data-table { min-width: 100%; font-size: 0.875rem; border-collapse: collapse; }
.data-table thead { background: #fafafa; }
.data-table th {
    padding: 0.875rem 1rem; text-align: left; font-size: 0.6875rem;
    font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #6b7280;
}
.data-table th.col-actions,
.data-table td.col-actions,
th.col-actions,
td.col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
    vertical-align: middle;
}
.data-table td { padding: 1rem; color: #374151; border-top: 1px solid #f3f4f6; }
.data-table tfoot td {
    padding: 1rem;
    border-top: 2px solid #e5e7eb;
    background: #f8fafc;
}
.data-table tbody tr:hover { background: #fafafa; }

.table-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.375rem;
    flex-wrap: nowrap;
}

.table-action-form {
    display: inline-flex;
    margin: 0;
}

.action-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #6b7280;
    text-decoration: none;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    flex-shrink: 0;
}

.action-icon-btn svg {
    width: 1rem;
    height: 1rem;
}

.action-icon-view:hover {
    color: #991b1b;
    border-color: #fecaca;
    background: #fef2f2;
}

.action-icon-edit:hover {
    color: #1d4ed8;
    border-color: #bfdbfe;
    background: #eff6ff;
}

.action-icon-delete:hover {
    color: #dc2626;
    border-color: #fecaca;
    background: #fef2f2;
}

button.action-icon-btn {
    padding: 0;
    cursor: pointer;
    font: inherit;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid #eef0f3;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.filter-bar .form-input {
    max-width: none;
    width: 100%;
}

.filter-bar .filter-field {
    flex: 0 1 auto;
    min-width: 11rem;
}

.filter-bar .filter-field .form-label {
    margin-bottom: 0.375rem;
}

.filter-bar .input-icon-wrap {
    flex: 1 1 220px;
    min-width: 220px;
}

.filter-bar .filter-control {
    flex: 0 1 auto;
    min-width: 11rem;
    width: auto;
}

.filter-bar select.form-input {
    flex-shrink: 0;
    cursor: pointer;
}

.filter-bar .btn,
.filter-bar .btn-primary,
.filter-bar .btn-secondary {
    flex-shrink: 0;
}

.date-period-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.date-period-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    border: 1px solid #e5e7eb;
    background: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #4b5563;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.date-period-btn:hover {
    border-color: #c7d2fe;
    background: #f8fafc;
    color: #4338ca;
}

.date-period-btn-active {
    border-color: #4f46e5;
    background: #4f46e5;
    color: #fff;
}

.date-period-btn-active:hover {
    border-color: #4338ca;
    background: #4338ca;
    color: #fff;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    padding-top: 0.5rem;
}

.page-header {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 1rem; margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.75rem; font-weight: 700; color: #111827; }

.nav-active {
    background: #fef2f2 !important; color: #991b1b !important;
    border-left: 3px solid #991b1b; font-weight: 600;
}

.login-panel-left {
    background: linear-gradient(145deg, #991b1b 0%, #5c1018 55%, #450a0a 100%);
    position: relative; overflow: hidden;
}
.login-panel-left::before {
    content: ''; position: absolute; inset: 0; opacity: 0.12;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.input-icon-wrap { position: relative; }
.input-icon-wrap svg {
    position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
    width: 1.125rem; height: 1.125rem; color: #9ca3af; pointer-events: none;
}
.input-icon-wrap .form-input { padding-left: 2.75rem; }

[x-cloak] { display: none !important; }

.resettle-row.resettle-row-active {
    border-color: #fca5a5;
    background: #fffbfb;
    box-shadow: 0 0 0 1px rgba(153, 27, 27, 0.08);
}

.resettle-fields .resettle-input {
    min-width: 0;
    width: 100%;
}

.resettle-fields .form-label {
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    color: #6b7280;
}

@media (min-width: 640px) {
    .resettle-fields .resettle-input {
        min-width: 9rem;
    }
}

.chart-card { border-radius: 1rem; border: 1px solid #eef0f3; background: #fff; padding: 1.25rem; }
.chart-card-title { font-size: 0.9375rem; font-weight: 600; color: #111827; margin-bottom: 1rem; }

.action-link { font-size: 0.8125rem; font-weight: 600; color: #991b1b; }
.action-link:hover { color: #5c1018; }
.action-link-muted { color: #6b7280; }
.action-link-muted:hover { color: #374151; }
.action-link-danger { color: #dc2626; }
.action-link-danger:hover { color: #b91c1c; }

button.action-link,
button.action-link-muted,
button.action-link-danger {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
}

@media (max-width: 1023px) {
    .page-header h2 { font-size: 1.375rem; }
    .kpi-card .kpi-value { font-size: 1.375rem; }
}

/* Mobile responsive layout */
html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
}

.app-main,
.app-content {
    min-width: 0;
}

.mobile-branch-filter select {
    max-width: 8.5rem;
}

.table-wrap {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    .card,
    .kpi-card,
    .chart-card {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .page-header-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .page-header-actions .btn,
    .page-header-actions .btn-primary,
    .page-header-actions .btn-secondary {
        width: 100%;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 0.875rem;
    }

    .filter-bar .input-icon-wrap,
    .filter-bar .filter-control,
    .filter-bar .filter-field,
    .filter-bar select.form-input,
    .filter-bar .form-input {
        flex: 1 1 100%;
        min-width: 0;
        width: 100%;
    }

    .filter-bar .btn,
    .filter-bar .btn-primary,
    .filter-bar .btn-secondary {
        width: 100%;
    }

    .date-period-shortcuts {
        gap: 0.375rem;
    }

    .date-period-btn {
        flex: 1 1 calc(50% - 0.375rem);
        justify-content: center;
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions .btn,
    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody tr {
        display: block;
        margin-bottom: 0.75rem;
        border: 1px solid #eef0f3;
        border-radius: 0.875rem;
        background: #fff;
        overflow: hidden;
    }

    .data-table tbody tr:hover {
        background: #fff;
    }

    .data-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.75rem 1rem;
        border-top: none;
        border-bottom: 1px solid #f3f4f6;
        text-align: right;
    }

    .data-table tbody td:last-child {
        border-bottom: none;
    }

    .data-table tbody td::before {
        content: attr(data-label);
        flex: 0 0 42%;
        max-width: 42%;
        text-align: left;
        font-size: 0.6875rem;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: #6b7280;
        line-height: 1.4;
        padding-top: 0.125rem;
    }

    .data-table tbody td[colspan] {
        display: block;
        text-align: center;
    }

    .data-table tbody td[colspan]::before {
        display: none;
    }

    .data-table tbody td.col-actions {
        align-items: center;
    }

    .data-table tbody td.col-actions::before {
        padding-top: 0.375rem;
    }

    .data-table tfoot {
        display: none;
    }

    .table-scroll-mobile {
        overflow-x: auto;
    }

    .table-scroll-mobile .data-table {
        min-width: 52rem;
    }

    .table-scroll-mobile .data-table thead {
        display: table-header-group;
    }

    .table-scroll-mobile .data-table tbody tr {
        display: table-row;
        margin-bottom: 0;
        border: none;
        border-radius: 0;
    }

    .table-scroll-mobile .data-table tbody td {
        display: table-cell;
        text-align: left;
        padding: 0.75rem 0.625rem;
        border-top: 1px solid #f3f4f6;
        border-bottom: none;
    }

    .table-scroll-mobile .data-table tbody td::before {
        display: none;
    }

    .table-scroll-mobile .data-table tfoot {
        display: table-footer-group;
    }
}
