/* ========================================
   TMS - Tenant & Expense Manager CSS
   Clean Minimalist & 100% Mobile Responsive
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #1a1a1a;
    --primary-light: #333333;
    --accent: #4a7c59;
    --accent-light: #5a9c6a;
    --accent-bg: rgba(74, 124, 89, 0.08);

    --bg-main: #f5f4f0;
    --bg-card: #ffffff;
    --bg-sidebar: #1a1a1a;
    --bg-hover: #f0efeb;
    --bg-input: #ffffff;

    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #888888;
    --text-light: #ffffff;

    --border: #e8e6e1;
    --border-focus: #1a1a1a;
    --border-light: #f0efeb;

    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --sidebar-width: 230px;
    --transition: all 0.2s ease;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    max-width: 100vw;
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Sidebar Desktop */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-light);
    height: 100vh;
    height: 100dvh;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand h2 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #ffffff;
}

.sidebar-brand .subtitle {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    margin-top: 2px;
}

.sidebar-menu {
    list-style: none;
    padding: 12px 10px;
    flex: 1;
}

.sidebar-menu li {
    margin: 2px 0;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    color: rgba(255,255,255,0.6);
    font-size: 13.5px;
    font-weight: 400;
    border-radius: var(--radius-sm);
    gap: 10px;
    transition: var(--transition);
}

.sidebar-menu li a:hover {
    color: #ffffff;
    background: rgba(255,255,255,0.08);
}

.sidebar-menu li a.active {
    color: #ffffff;
    background: rgba(255,255,255,0.12);
    font-weight: 500;
}

.sidebar-menu li a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar-menu li a.active svg {
    opacity: 1;
}

.sidebar-user {
    padding: 16px 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-info .user-name {
    font-size: 13px;
    font-weight: 500;
    color: #fff;
}

.sidebar-user-info .user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

/* Main Layout */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100vw;
    box-sizing: border-box;
}

.top-header {
    padding: 24px 32px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    word-break: break-word;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle {
    cursor: pointer;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--bg-hover);
}

.theme-toggle svg {
    width: 17px;
    height: 17px;
}

.content-area {
    padding: 20px 32px 40px;
    flex: 1;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    width: 100%;
    box-sizing: border-box;
}

.card-header h3 {
    font-size: 14.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    word-break: break-word;
    min-width: 0;
}

/* Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: var(--transition);
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

.stat-card .stat-number {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    word-break: break-word;
}

.stat-card .stat-sub {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-card .stat-sub.positive { color: var(--success); }
.stat-card .stat-sub.negative { color: var(--danger); }

/* Chart Containers - Strict Responsive */
.chart-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    height: 260px;
    overflow: hidden;
    min-width: 0;
    box-sizing: border-box;
}

.chart-container canvas {
    max-width: 100% !important;
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Tables */
.table-responsive {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    display: block;
    box-sizing: border-box;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 450px;
}

table thead {
    border-bottom: 1px solid var(--border);
}

table th {
    padding: 9px 12px;
    text-align: left;
    font-weight: 500;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    white-space: nowrap;
}

table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

table tbody tr:hover {
    background: var(--bg-hover);
}

table tbody tr:last-child td {
    border-bottom: none;
}

/* Forms */
.form-group {
    margin-bottom: 14px;
    width: 100%;
    box-sizing: border-box;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 5px;
    font-size: 12.5px;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    max-width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
    box-sizing: border-box;
}

.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(26,26,26,0.06);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    width: 100%;
    box-sizing: border-box;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    width: 100%;
    box-sizing: border-box;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-hover); border-color: var(--text-secondary); }

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 6px; min-width: 30px; height: 30px; border-radius: var(--radius-sm); display: inline-flex; align-items: center; justify-content: center; }
.btn-sm.btn-icon { padding: 4px; min-width: 26px; height: 26px; }
.btn-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 50px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-success { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.badge-warning { background: rgba(217, 119, 6, 0.1); color: var(--warning); }
.badge-danger { background: rgba(220, 38, 38, 0.1); color: var(--danger); }
.badge-info { background: rgba(2, 132, 199, 0.1); color: var(--info); }
.badge-secondary { background: var(--bg-hover); color: var(--text-secondary); }

/* Alerts */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 12.5px;
    font-weight: 500;
    border: 1px solid;
    width: 100%;
    box-sizing: border-box;
}
.alert-success { background: rgba(22, 163, 74, 0.08); color: var(--success); border-color: rgba(22, 163, 74, 0.2); }
.alert-danger { background: rgba(220, 38, 38, 0.08); color: var(--danger); border-color: rgba(220, 38, 38, 0.2); }

.empty-state {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-muted);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 14px;
    overflow-y: auto;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 100%;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
}

/* Responsive Grid Utility Classes */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1.2fr;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.grid-1-2 {
    display: grid;
    grid-template-columns: 1.2fr 2fr;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    width: 100%;
    box-sizing: border-box;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    width: 100%;
    box-sizing: border-box;
}

/* Document / Agreement Viewer */
.doc-viewer-box {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-hover);
    padding: 14px;
    margin-top: 12px;
    text-align: center;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.doc-viewer-box img {
    max-width: 100%;
    max-height: 480px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    border: 1px solid var(--border);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease;
}

.doc-viewer-box img:hover {
    transform: scale(1.01);
}

.doc-viewer-box iframe {
    width: 100%;
    height: 480px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    box-sizing: border-box;
}

/* Mobile Navbar & Controls */
.mobile-navbar {
    display: none;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    z-index: 900;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

.mobile-brand {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.hamburger-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.hamburger-btn:hover {
    background: var(--bg-hover);
}

.sidebar-close-btn {
    display: none;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(2px);
    z-index: 998;
}
.sidebar-overlay.show { display: block; }

body.sidebar-locked {
    overflow: hidden;
}

/* ========================================
   RESPONSIVE BREAKPOINTS (AIRTIGHT NO-OVERFLOW)
   ======================================== */
@media (max-width: 992px) {
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,0.3);
        width: 270px;
        max-width: 82vw;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close-btn {
        display: block;
    }
    .mobile-navbar {
        display: flex !important;
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        display: block !important;
        min-height: auto;
        overflow-x: hidden;
    }
    .top-header {
        padding: 14px 16px 0 !important;
    }
    .content-area {
        padding: 14px 16px 30px !important;
        overflow-x: hidden;
    }
    .grid-2, .grid-2-1, .grid-1-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
    .form-row, .form-row-3 {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
}

@media (max-width: 576px) {
    .top-header {
        padding: 10px 12px 0 !important;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    .top-header .header-actions {
        display: none !important;
    }
    .page-title {
        font-size: 19px !important;
    }
    .content-area {
        padding: 10px 12px 24px !important;
    }
    .card {
        padding: 14px !important;
        border-radius: var(--radius-sm);
        margin-bottom: 12px;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 14px;
        padding-bottom: 10px;
    }
    .card-header .btn-group, .card-header .btn {
        width: 100%;
        justify-content: center;
    }
    .dashboard-stats {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        margin-bottom: 14px;
    }
    .stat-card {
        padding: 12px 10px !important;
    }
    .stat-card .stat-label {
        font-size: 10px;
    }
    .stat-card .stat-number {
        font-size: 17px !important;
    }
    .stat-card .stat-sub {
        font-size: 10.5px;
    }
    .chart-container {
        height: 220px !important;
    }
    .btn-group {
        width: 100%;
        gap: 6px;
    }
    .btn-group .btn {
        flex: 1 1 auto;
        min-width: 100px;
        font-size: 11.5px;
        padding: 7px 10px;
    }
    .doc-viewer-box iframe {
        height: 300px;
    }
    .modal-card {
        padding: 16px;
        width: 95vw;
    }
    table th, table td {
        padding: 7px 9px;
        font-size: 12px;
    }
}

@media (max-width: 380px) {
    .dashboard-stats {
        grid-template-columns: 1fr !important;
    }
}

/* Print Styles */
@media print {
    .sidebar, .top-header, .mobile-navbar, .print-hide, .btn, .header-actions, .sidebar-overlay {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        padding: 12px !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
}