/**
 * Gestor Financeiro Pessoal - Custom Styles
 * Complementary CSS for TailwindCSS
 */

/* =====================================================
   CSS Variables & Theme
   ===================================================== */
:root {
    --color-primary: #10b981;
    --color-primary-dark: #059669;
    --color-primary-light: #34d399;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #3b82f6;

    /* Light theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.1);

    /* Sidebar */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 64px;
}

.dark {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

/* =====================================================
   Base Styles
   ===================================================== */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background-color: var(--text-muted);
    border-radius: 3px;
}

body {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* =====================================================
   Layout
   ===================================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    transition: margin-left 0.3s ease;
}

.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

@media (max-width: 1023px) {
    .main-content {
        margin-left: 0;
    }
}

/* =====================================================
   Sidebar
   ===================================================== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    border-right: 1px solid var(--border-color);
    z-index: 40;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-collapsed .sidebar .nav-text,
.sidebar-collapsed .sidebar .sidebar-logo-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

@media (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 35;
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
    }
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--color-primary) 0%, #14b8a6 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.sidebar-logo-text {
    font-weight: 700;
    font-size: 1.125rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, #14b8a6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    transition: opacity 0.2s, width 0.3s;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-group {
    margin-bottom: 1.5rem;
}

.nav-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.sidebar-collapsed .nav-group-title {
    opacity: 0;
    height: 0;
    margin: 0;
    overflow: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    margin-bottom: 0.25rem;
    position: relative;
    overflow: hidden;
}

.nav-item:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(20, 184, 166, 0.1) 100%);
    color: var(--color-primary);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: linear-gradient(180deg, var(--color-primary) 0%, #14b8a6 100%);
    border-radius: 0 2px 2px 0;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-text {
    white-space: nowrap;
    transition: opacity 0.2s, width 0.3s;
}

/* =====================================================
   Topbar
   ===================================================== */
.topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 30;
    transition: left 0.3s ease;
    backdrop-filter: blur(10px);
    background: rgba(var(--bg-primary), 0.8);
}

.sidebar-collapsed .topbar {
    left: var(--sidebar-collapsed-width);
}

@media (max-width: 1023px) {
    .topbar {
        left: 0;
    }
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.hamburger-icon {
    width: 20px;
    height: 20px;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* =====================================================
   Period Selector
   ===================================================== */
.period-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-tertiary);
    padding: 0.5rem;
    border-radius: 12px;
}

.period-selector select {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 16px;
    transition: all 0.2s ease;
}

.period-selector select:hover,
.period-selector select:focus {
    border-color: var(--color-primary);
    outline: none;
}

/* =====================================================
   User Menu
   ===================================================== */
.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-menu-btn:hover {
    background: var(--bg-tertiary);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.user-info {
    text-align: left;
    display: none;
}

@media (min-width: 640px) {
    .user-info {
        display: block;
    }
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

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

.user-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 200px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px var(--shadow-color);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 50;
    overflow: hidden;
}

.user-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-danger);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

/* =====================================================
   Theme Toggle
   ===================================================== */
.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--color-primary);
    color: white;
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.theme-toggle .sun-icon {
    display: none;
}

.dark .theme-toggle .sun-icon {
    display: block;
}

.dark .theme-toggle .moon-icon {
    display: none;
}

/* =====================================================
   Cards
   ===================================================== */
.card {
    background: var(--bg-primary);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    transition: all 0.2s ease;
}

.card:hover {
    box-shadow: 0 8px 30px var(--shadow-color);
}

.card-kpi {
    position: relative;
    overflow: hidden;
}

.card-kpi::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    opacity: 0.1;
    transform: translate(30%, -30%);
}

.card-kpi.income::before {
    background: var(--color-success);
}

.card-kpi.expense::before {
    background: var(--color-danger);
}

.card-kpi.balance::before {
    background: var(--color-primary);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.kpi-icon.income {
    background: rgba(34, 197, 94, 0.15);
    color: var(--color-success);
}

.kpi-icon.expense {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
}

.kpi-icon.balance {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-primary);
}

.kpi-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.kpi-value.positive {
    color: var(--color-success);
}

.kpi-value.negative {
    color: var(--color-danger);
}

/* =====================================================
   Charts Container
   ===================================================== */
.chart-container {
    position: relative;
    height: 300px;
}

@media (max-width: 640px) {
    .chart-container {
        height: 250px;
    }
}

/* =====================================================
   Modal
   ===================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-primary);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px var(--shadow-color);
    z-index: 101;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--color-danger);
    color: white;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* =====================================================
   Forms
   ===================================================== */
.form-group {
    margin-bottom: 1.25rem;
}

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

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9375rem;
    transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 20px;
    padding-right: 2.5rem;
    cursor: pointer;
}

/* Type Toggle */
.type-toggle {
    display: flex;
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 4px;
    gap: 4px;
}

.type-toggle-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    color: var(--text-secondary);
}

.type-toggle-btn.active {
    color: white;
}

.type-toggle-btn.income.active {
    background: var(--color-success);
}

.type-toggle-btn.expense.active {
    background: var(--color-danger);
}

/* =====================================================
   Buttons
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, #14b8a6 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

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

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

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 10px;
}

/* =====================================================
   Budget Table
   ===================================================== */
.budget-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

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

.budget-table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-secondary);
}

.budget-table th:first-child {
    border-radius: 10px 0 0 0;
}

.budget-table th:last-child {
    border-radius: 0 10px 0 0;
}

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

.budget-table tr:hover td {
    background: var(--bg-secondary);
}

.budget-input {
    width: 120px;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-primary);
    text-align: right;
    font-size: 0.9375rem;
    transition: all 0.2s ease;
}

.budget-input:focus {
    border-color: var(--color-primary);
    background: var(--bg-primary);
    outline: none;
}

.category-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.category-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.difference-positive {
    color: var(--color-success);
    font-weight: 600;
}

.difference-negative {
    color: var(--color-danger);
    font-weight: 600;
}

.over-budget-alert {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-danger);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* =====================================================
   Transaction List
   ===================================================== */
.transaction-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 12px;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
}

.transaction-item:hover {
    background: var(--bg-secondary);
}

.transaction-item.clickable {
    cursor: pointer;
}

.transaction-item.clickable:hover {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.transaction-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.transaction-info {
    flex: 1;
    min-width: 0;
}

.transaction-category {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
}

.transaction-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.transaction-amount {
    font-weight: 700;
    font-size: 1rem;
}

.transaction-amount.income {
    color: var(--color-success);
}

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

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

/* =====================================================
   Loading & Empty States
   ===================================================== */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    opacity: 0.5;
}

/* =====================================================
   Toast Notifications
   ===================================================== */
.toast-container {
    position: fixed;
    top: calc(var(--topbar-height) + 1rem);
    right: 1rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px var(--shadow-color);
    min-width: 300px;
    max-width: 400px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

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

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

/* =====================================================
   Responsive Utilities
   ===================================================== */

/* ===== UNIVERSAL FLUID RESPONSIVE BASE ===== */
/* These rules ensure content adapts to ANY screen size */

/* Box sizing for predictable sizing */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Prevent any element from exceeding viewport */
img,
video,
iframe,
table {
    max-width: 100%;
}

/* SVGs should respect viewport except in buttons/icons */
svg:not(.btn svg):not(.btn-icon svg):not(.nav-icon):not(.hamburger-icon):not(.kpi-icon svg):not(.transaction-icon svg) {
    max-width: 100%;
}

/* Ensure button icons maintain their size */
.btn svg,
.btn-icon svg,
.nav-icon,
.hamburger-icon {
    flex-shrink: 0;
    min-width: 16px;
    min-height: 16px;
}

/* Flex children must be able to shrink */
.topbar-left,
.topbar-right,
.period-selector,
.user-menu,
.transaction-item,
.category-cell,
.flex {
    min-width: 0;
}

/* Main layout containers respect viewport */
.app-layout {
    max-width: 100vw;
}

.main-content {
    min-width: 0;
    max-width: 100%;
}

/* Topbar must stay within viewport */
.topbar {
    max-width: 100%;
    box-sizing: border-box;
}

.topbar-right {
    flex-shrink: 1;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Period selector flexible sizing */
.period-selector {
    flex-shrink: 1;
}

.period-selector select {
    min-width: 0;
    max-width: 100%;
}

/* Cards flexible sizing */
.card {
    min-width: 0;
    max-width: 100%;
}

/* KPI values wrap if needed */
.kpi-value {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Transaction list items flexible */
.transaction-info {
    min-width: 0;
    flex: 1;
}

/* Toast notifications respect viewport */
.toast {
    max-width: calc(100vw - 2rem);
}

/* ===== MOBILE DEVICES (< 768px) ===== */
@media (max-width: 767px) {

    /* Allow horizontal scroll ONLY on specific containers, not body */
    .main-content {
        padding-top: calc(var(--topbar-height) - 8px);
    }

    main {
        padding: 0.75rem !important;
    }

    /* Topbar mobile */
    .topbar {
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .topbar-left {
        gap: 0.5rem;
    }

    .topbar-right {
        gap: 0.5rem;
    }

    /* Period selector - compact on mobile */
    .period-selector {
        padding: 0.25rem;
        gap: 0.25rem;
        border-radius: 8px;
    }

    .period-selector select {
        padding: 0.4rem 1.5rem 0.4rem 0.5rem;
        font-size: 0.75rem;
        border-radius: 6px;
        min-width: 0;
        background-size: 12px;
        background-position: right 0.25rem center;
    }

    /* Theme toggle smaller */
    .theme-toggle {
        width: 34px;
        height: 34px;
        border-radius: 8px;
    }

    .theme-toggle svg {
        width: 16px;
        height: 16px;
    }

    /* User menu smaller */
    .user-avatar {
        width: 34px;
        height: 34px;
        border-radius: 8px;
    }

    .user-menu-btn {
        padding: 0.25rem;
    }

    /* Hamburger button */
    .hamburger-btn {
        width: 34px;
        height: 34px;
    }

    /* Cards mobile */
    .card {
        padding: 0.875rem;
        border-radius: 12px;
    }

    .card-kpi {
        padding: 1rem;
    }

    .kpi-icon {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        margin-bottom: 0.75rem;
    }

    .kpi-icon svg {
        width: 20px;
        height: 20px;
    }

    .kpi-label {
        font-size: 0.75rem;
    }

    .kpi-value {
        font-size: 1.25rem;
    }

    /* Charts smaller on mobile */
    .chart-container {
        height: 200px;
    }

    /* Transaction items mobile */
    .transaction-item {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .transaction-icon {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    .transaction-icon svg {
        width: 16px;
        height: 16px;
    }

    .transaction-category {
        font-size: 0.875rem;
    }

    .transaction-description {
        font-size: 0.75rem;
    }

    .transaction-amount {
        font-size: 0.875rem;
    }

    .transaction-date {
        font-size: 0.625rem;
    }

    /* Budget table mobile - horizontal scroll within container */
    .budget-table {
        font-size: 0.75rem;
        display: block;
        width: 100%;
    }

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

    /* Remove min-width constraints on mobile */
    .budget-table th[class*="min-w"],
    .budget-table td[class*="min-w"] {
        min-width: unset !important;
    }

    .budget-input {
        width: 65px;
        padding: 0.375rem;
        font-size: 0.75rem;
    }

    .category-cell {
        gap: 0.5rem;
    }

    .category-dot {
        width: 8px;
        height: 8px;
    }

    /* Overflow container for tables */
    .overflow-x-auto {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Toasts mobile */
    .toast-container {
        left: 0.5rem;
        right: 0.5rem;
        top: calc(var(--topbar-height) + 0.5rem);
    }

    .toast {
        min-width: auto;
        max-width: 100%;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    /* Buttons mobile */
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
    }

    /* Modal mobile */
    .modal {
        width: 95%;
        max-height: 85vh;
        border-radius: 16px;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }

    .modal-title {
        font-size: 1.125rem;
    }

    /* Empty state mobile */
    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-state-icon {
        width: 48px;
        height: 48px;
    }

    /* Form inputs mobile - 16px prevents iOS zoom */
    .form-input,
    .form-select,
    .form-textarea {
        padding: 0.625rem 0.875rem;
        font-size: 16px;
    }

    /* Grid adjustments */
    .grid {
        gap: 0.75rem !important;
    }

    /* Hide page title on mobile */
    .page-title {
        display: none !important;
    }

    /* Flex items wrap */
    .flex.items-center.justify-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Over budget alert compact */
    .over-budget-alert {
        padding: 0.125rem 0.375rem;
        font-size: 0.625rem;
    }

    .over-budget-alert svg {
        width: 12px;
        height: 12px;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .hide-tablet {
        display: none !important;
    }
}

@media (min-width: 1024px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* =====================================================
   Print Styles
   ===================================================== */
@media print {
    @page {
        size: A4;
        margin: 1.5cm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
        color: black !important;
        font-size: 11pt;
    }

    .sidebar,
    .topbar,
    .hamburger-btn,
    .theme-toggle,
    .user-menu,
    .modal-backdrop,
    .modal,
    .toast-container,
    .btn,
    .no-print {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .card {
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .chart-container {
        height: 200px !important;
    }

    .budget-table {
        width: 100%;
    }

    .budget-table th {
        background: #f3f4f6 !important;
    }

    .budget-input {
        border: none !important;
        background: transparent !important;
        text-align: right;
    }

    .kpi-value {
        font-size: 14pt;
    }

    a {
        text-decoration: none;
        color: inherit;
    }

    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
        border-bottom: 2px solid #10b981;
    }

    .print-header h1 {
        font-size: 16pt;
        margin: 0;
    }

    .print-header p {
        font-size: 10pt;
        color: #666;
        margin: 0.5rem 0 0;
    }

    .print-footer {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        text-align: center;
        font-size: 9pt;
        color: #999;
        padding: 0.5rem;
        border-top: 1px solid #ddd;
    }
}

.print-header,
.print-footer {
    display: none;
}

/* =====================================================
   Animations
   ===================================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease;
}

.animate-slide-up {
    animation: slideUp 0.3s ease;
}