/* ========================================
   CASHFLOW SYSTEM - MOBILE-FIRST RESPONSIVE CSS
   ======================================== */

/* === RESET & BASE === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === MOBILE-FIRST LAYOUT === */
.container {
    width: 100%;
    padding: 15px;
    margin: 0 auto;
}

/* === HEADER === */
.header {
    background: #3aaf3a;
    border-bottom: 3px solid #2d8f2d;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    position: relative;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.logo img {
    height: 34px;
    display: block;
    filter: brightness(0) invert(1);
}

/* === MOBILE NAVIGATION === */
.mobile-menu-toggle {
    display: block;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #fff;
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: #fff;
    margin: 5px 0;
    transition: all 0.3s;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

.nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #3aaf3a;
    border-top: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 6px 12px rgba(0,0,0,0.25);
    flex-direction: column;
    padding: 8px 0;
}

.nav-links.active {
    display: flex;
}

.nav-links a {
    color: #fff;
    text-decoration: none;
    padding: 11px 20px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-links a:hover,
.nav-links a:active {
    background: rgba(0,0,0,0.12);
    color: #fff;
    border-left-color: #fff;
}

/* Dropdown навигация */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: inherit;
    font-family: inherit;
    font-weight: inherit;
    line-height: inherit;
    cursor: pointer;
    padding: 11px 20px;
    display: block;
    width: 100%;
    text-align: left;
    border-left: 3px solid transparent;
}

.nav-dropdown-toggle:hover {
    background: rgba(0,0,0,0.12);
    border-left-color: #fff;
}

.nav-dropdown-menu {
    display: none;
    flex-direction: column;
    background: rgba(0,0,0,0.15);
}

.nav-dropdown-menu.open { display: flex; }

.nav-dropdown-menu a {
    padding: 9px 20px 9px 32px;
    font-size: 13px;
}

/* Desktop dropdown */
@media (min-width: 768px) {
    .nav-dropdown { position: relative; }

    .nav-dropdown-toggle {
        padding: 7px 13px;
        border-left: none;
        border-radius: 6px;
        font-size: 14px;
        font-family: inherit;
        font-weight: inherit;
        line-height: inherit;
        opacity: 0.9;
        vertical-align: middle;
    }

    .nav-dropdown-toggle:hover {
        background: rgba(0,0,0,0.12);
        opacity: 1;
        border-left: none;
    }

    .nav-dropdown-menu {
        position: absolute;
        top: calc(100% + 4px);
        right: 0;
        min-width: 160px;
        background: #fff;
        border-radius: 6px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.15);
        z-index: 1000;
        padding: 4px 0;
    }

    .nav-dropdown-menu.open { display: flex; }

    .nav-links .nav-dropdown-menu a {
        color: #333 !important;
        padding: 8px 16px;
        font-size: 14px;
        border-radius: 0;
        border: none !important;
        background: none;
    }

    .nav-links .nav-dropdown-menu a:hover {
        background: #f0f4f8 !important;
        color: #1565c0 !important;
        border-left: none !important;
    }
}

/* User info - mobile */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-details {
    display: none;
    text-align: right;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}

.user-role {
    background: rgba(0,0,0,0.18);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    display: inline-block;
    margin-top: 2px;
}

/* === ALERTS === */
.alert {
    padding: 12px 15px;
    margin-bottom: 15px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 14px;
}

.alert-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
}

.alert-info {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

/* === BUTTONS === */
.btn {
    display: inline-block;
    padding: 10px 16px;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    text-align: center;
    min-height: 44px;
    line-height: 1.5;
}

.btn:hover,
.btn:active {
    background: #5568d3;
    transform: translateY(-1px);
}

.btn-success {
    background: #28a745;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
}

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

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

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

.btn-warning {
    background: #ffc107;
    color: #333;
}

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

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
    min-height: 36px;
}

.btn-block {
    display: block;
    width: 100%;
}

/* Button groups - stack on mobile */
.btn-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.btn-group .btn {
    margin: 0;
}

/* === CARDS === */
.card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.card-header {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
    color: #333;
}

/* === STATS GRID === */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.stat-label {
    color: #666;
    font-size: 13px;
    margin-bottom: 6px;
    font-weight: 500;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    word-break: break-word;
}

.stat-value.positive {
    color: #28a745;
}

.stat-value.negative {
    color: #dc3545;
}

/* === FORMS === */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    background: white;
    transition: border-color 0.2s;
    min-height: 44px;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

select.form-control {
    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='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* Input types for mobile */
input[type="number"].form-control,
input[type="tel"].form-control {
    font-size: 16px; /* Prevents zoom on iOS */
}

/* === TABLES === */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 15px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px; /* Prevents table from being too cramped */
}

table th {
    background: #f8f9fa;
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
    font-size: 13px;
    white-space: nowrap;
}

table td {
    padding: 10px 8px;
    border-bottom: 1px solid #dee2e6;
    font-size: 14px;
}

table tr:hover {
    background: #f8f9fa;
}

/* Responsive table - card layout for very small screens */
@media (max-width: 480px) {
    .table-responsive-stack {
        min-width: 100%;
    }

    .table-responsive-stack thead {
        display: none;
    }

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

    .table-responsive-stack tr {
        margin-bottom: 15px;
        border: 1px solid #dee2e6;
        border-radius: 6px;
        background: white;
    }

    .table-responsive-stack td {
        text-align: right;
        padding: 10px;
        position: relative;
        border-bottom: 1px solid #f0f0f0;
    }

    .table-responsive-stack td:last-child {
        border-bottom: none;
    }

    .table-responsive-stack td:before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #666;
    }
}

/* Compact table view for mobile - structured card layout */
@media (max-width: 767px) {
    .table-compact thead {
        display: none;
    }

    .table-compact tbody tr {
        display: block;
        margin-bottom: 10px;
        padding: 10px;
        border: 1px solid #dee2e6;
        border-radius: 6px;
        background: white;
        font-size: 13px;
    }

    .table-compact tbody td {
        display: flex;
        align-items: center;
        padding: 6px 0;
        border: none;
        word-wrap: break-word;
        border-bottom: 1px solid #f0f0f0;
        min-height: 32px;
        gap: 8px;
        text-align: left;
    }

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

    .table-compact tbody td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #999;
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        flex-shrink: 0;
        width: 80px;
        text-align: left;
    }

    .table-compact tbody td[data-label="Действия"]:before {
        display: none;
    }

    .table-compact tbody td[data-label="Действия"] {
        border-bottom: none;
        padding-top: 8px;
        padding-bottom: 0;
        min-height: auto;
    }

    .table-compact tbody td[data-label="Действия"]:before {
        width: 0;
    }

    .table-compact .action-cell {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
        align-items: center;
    }

    .table-compact .badge {
        font-size: 11px;
        padding: 3px 8px;
        display: inline-block;
        line-height: 1.4;
    }

    .table-compact .btn-small {
        padding: 13px 6px;
        font-size: 10px;
        line-height: 1.2;
    }

    .table-compact strong {
        font-weight: 600;
        color: #333;
    }
}

/* === BADGES === */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-warning {
    background: #fff3cd;
    color: #856404;
}

.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}

.badge-secondary {
    background: #e2e3e5;
    color: #383d41;
}

/* === UTILITY CLASSES === */
.text-center {
    text-align: center;
}

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

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }

/* === LOADING SPINNER === */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   TABLET BREAKPOINT (min-width: 768px)
   ======================================== */
@media (min-width: 768px) {
    .container {
        padding: 20px 30px;
    }

    .logo {
        font-size: 22px;
    }

    .mobile-menu-toggle {
        display: none;
    }

    .nav-links {
        display: flex;
        position: static;
        flex-direction: row;
        gap: 4px;
        box-shadow: none;
        border: none;
        padding: 0;
        flex-wrap: wrap;
    }

    .nav-links a {
        padding: 7px 13px;
        border-left: none;
        border-radius: 6px;
        font-size: 13px;
        color: #fff;
        border: 1px solid transparent;
    }

    .nav-links a:hover {
        background: rgba(0,0,0,0.12);
        color: #fff;
        border-left: none;
        border-color: rgba(255,255,255,0.3);
    }

    .user-details {
        display: block;
    }

    .user-name {
        font-size: 14px;
    }

    .user-role {
        font-size: 11px;
    }

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

    .stat-value {
        font-size: 28px;
    }

    .btn-group {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .card {
        padding: 20px;
    }

    .card-header {
        font-size: 20px;
    }
}

/* ========================================
   DESKTOP BREAKPOINT (min-width: 1024px)
   ======================================== */
@media (min-width: 1024px) {
    .container {
        max-width: 1400px;
        padding: 30px 20px;
    }

    .header-content {
        max-width: 1400px;
        margin: 0 auto;
        padding: 15px 20px;
    }

    .logo {
        font-size: 24px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 24px;
        margin-bottom: 30px;
    }

    .stat-card {
        padding: 24px;
    }

    .stat-value {
        font-size: 32px;
    }

    .card {
        padding: 24px;
    }

    table th,
    table td {
        padding: 12px;
    }

    .btn {
        padding: 12px 24px;
        font-size: 15px;
    }
}

/* ========================================
   LARGE DESKTOP (min-width: 1440px)
   ======================================== */
@media (min-width: 1440px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .header,
    .nav-links,
    .btn,
    .mobile-menu-toggle {
        display: none;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
