/* ============================================
   RENTAL APPLICATION - MOBILE-FIRST CSS
   Design for 320px+ screens first, scale up
   ============================================ */

:root {
    --primary: #0056b3;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --light: #f8f9fa;
    --dark: #343a40;
    
    /* Mobile-optimized spacing */
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Touch-friendly sizes */
    --min-tap-target: 44px;
    --input-height: 48px;
    --button-height: 48px;
}

/* ============================================
   BASE STYLES - MOBILE FIRST
   ============================================ */

* {
    box-sizing: border-box;
}

html {
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f5f5;
    margin: 0;
    padding: 0;
    /* Readable without zooming on mobile */
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
}

.container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: var(--spacing-md);
}

/* Desktop: wider container */
@media (min-width: 768px) {
    .container {
        max-width: 1200px;
        padding: var(--spacing-lg);
    }
}

/* ============================================
   CARDS
   ============================================ */

.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: var(--spacing-lg);
    overflow: hidden;
}

.card-header {
    background: var(--primary);
    color: white;
    padding: var(--spacing-md);
    font-weight: 600;
    font-size: 1.125rem; /* 18px */
}

.card-body {
    padding: var(--spacing-md);
}

/* Desktop: more padding */
@media (min-width: 768px) {
    .card-header {
        padding: var(--spacing-lg);
        font-size: 1.25rem;
    }
    
    .card-body {
        padding: var(--spacing-lg);
    }
}

/* ============================================
   FORMS - MOBILE OPTIMIZED
   ============================================ */

.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
    color: #333;
    font-size: 1rem; /* 16px - readable on mobile */
}

.form-control,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    /* Touch-friendly height */
    min-height: var(--input-height);
    padding: var(--spacing-sm) var(--spacing-md);
    border: 2px solid #ddd;
    border-radius: 6px;
    /* Prevent zoom on iOS */
    font-size: 16px;
    box-sizing: border-box;
    appearance: none;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Mobile keyboard hints */
input[type="tel"] {
    /* Triggers numeric keyboard with symbols */
}

input[type="email"] {
    /* Triggers email keyboard */
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,86,179,0.1);
}

.form-control.is-invalid,
input.is-invalid,
select.is-invalid,
textarea.is-invalid {
    border-color: var(--danger);
}

.invalid-feedback {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: var(--spacing-xs);
    display: block;
}

/* Select dropdown arrow */
select {
    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: 40px;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

/* ============================================
   BUTTONS - TOUCH OPTIMIZED
   ============================================ */

.btn {
    display: inline-block;
    /* Touch-friendly minimum */
    min-height: var(--button-height);
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    text-align: center;
    line-height: 1.5;
    /* Prevent text selection on tap */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary:hover,
.btn-primary:active {
    background: #004494;
}

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

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

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

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

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

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

.btn-lg {
    min-height: 56px;
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: 1.125rem;
}

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

/* Touch feedback */
.btn:active {
    transform: scale(0.98);
}

/* ============================================
   ALERTS
   ============================================ */

.alert {
    padding: var(--spacing-md);
    border-radius: 6px;
    margin-bottom: var(--spacing-lg);
    font-size: 0.9375rem;
}

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

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

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

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

.alert a {
    color: inherit;
    text-decoration: underline;
    font-weight: 600;
}

/* ============================================
   BADGES
   ============================================ */

.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-draft { background: #e9ecef; color: #495057; }
.badge-sent { background: #cce5ff; color: #004085; }
.badge-opened { background: #fff3cd; color: #856404; }
.badge-submitted { background: #d1ecf1; color: #0c5460; }
.badge-reviewed { background: #d4edda; color: #155724; }
.badge-approved { background: #28a745; color: white; }
.badge-denied { background: #dc3545; color: white; }

/* ============================================
   PROPERTY INFO BLOCK
   ============================================ */

.property-info {
    background: var(--light);
    padding: var(--spacing-md);
    border-radius: 6px;
    margin-bottom: var(--spacing-lg);
    border-left: 4px solid var(--primary);
}

.property-info h3 {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--primary);
    font-size: 1.25rem;
}

.property-info .detail {
    margin: var(--spacing-xs) 0;
    font-size: 0.9375rem;
    /* Stack labels on mobile */
    display: block;
}

.property-info .detail strong {
    display: block;
    margin-bottom: 4px;
    color: #666;
}

/* Desktop: inline labels */
@media (min-width: 768px) {
    .property-info {
        padding: var(--spacing-lg);
    }
    
    .property-info .detail {
        display: flex;
    }
    
    .property-info .detail strong {
        display: inline-block;
        min-width: 180px;
        margin-bottom: 0;
        margin-right: var(--spacing-md);
    }
}

/* ============================================
   SECTION HEADERS
   ============================================ */

.section-header {
    background: var(--light);
    padding: var(--spacing-md);
    margin: var(--spacing-lg) calc(-1 * var(--spacing-md)) var(--spacing-md);
    border-left: 4px solid var(--primary);
    font-weight: 600;
    font-size: 1.125rem;
}

/* Desktop: wider negative margin */
@media (min-width: 768px) {
    .section-header {
        margin-left: calc(-1 * var(--spacing-lg));
        margin-right: calc(-1 * var(--spacing-lg));
        padding: var(--spacing-md) var(--spacing-lg);
    }
}

/* ============================================
   LEASE PROVISIONS
   ============================================ */

.lease-provisions {
    background: #fffbf0;
    border: 2px solid #ffc107;
    padding: var(--spacing-md);
    margin: var(--spacing-lg) 0;
    border-radius: 6px;
}

.lease-provisions h4 {
    margin: 0 0 var(--spacing-md) 0;
    color: #856404;
    font-size: 1.125rem;
}

.lease-provisions ol {
    margin: 0;
    padding-left: var(--spacing-lg);
}

.lease-provisions li {
    margin-bottom: var(--spacing-sm);
    line-height: 1.6;
}

@media (min-width: 768px) {
    .lease-provisions {
        padding: var(--spacing-lg);
    }
}

/* ============================================
   SIGNATURE BOX
   ============================================ */

.signature-box {
    background: var(--light);
    padding: var(--spacing-md);
    border-radius: 6px;
    margin-top: var(--spacing-lg);
}

.signature-box p {
    line-height: 1.6;
}

@media (min-width: 768px) {
    .signature-box {
        padding: var(--spacing-lg);
    }
}

/* ============================================
   CHECKBOXES - TOUCH OPTIMIZED
   ============================================ */

.checkbox-group {
    margin: var(--spacing-md) 0;
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
}

.checkbox-group input[type="checkbox"] {
    /* Touch-friendly checkbox */
    width: 24px;
    height: 24px;
    min-width: 24px;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-group label {
    font-weight: normal;
    cursor: pointer;
    line-height: 1.6;
    margin: 0;
}

/* ============================================
   TABLES - MOBILE RESPONSIVE
   ============================================ */

/* Mobile: card-based view */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--spacing-md) 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--spacing-md) 0;
}

/* Mobile: hide table, show card layout */
@media (max-width: 767px) {
    .table thead {
        display: none;
    }
    
    .table tbody {
        display: block;
    }
    
    .table tr {
        display: block;
        margin-bottom: var(--spacing-md);
        background: white;
        border-radius: 6px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        padding: var(--spacing-md);
    }
    
    .table td {
        display: block;
        text-align: left;
        padding: var(--spacing-xs) 0;
        border: none;
    }
    
    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        display: block;
        color: #666;
        font-size: 0.875rem;
        margin-bottom: 4px;
    }
    
    .table td:first-child {
        font-size: 1.125rem;
        font-weight: 600;
        padding-bottom: var(--spacing-sm);
        border-bottom: 1px solid #eee;
        margin-bottom: var(--spacing-sm);
    }
}

/* Desktop: traditional table */
@media (min-width: 768px) {
    .table th {
        background: var(--light);
        padding: var(--spacing-md);
        text-align: left;
        font-weight: 600;
        border-bottom: 2px solid #dee2e6;
    }
    
    .table td {
        padding: var(--spacing-md);
        border-bottom: 1px solid #dee2e6;
    }
    
    .table tbody tr:hover {
        background: #f8f9fa;
    }
}

/* ============================================
   STATS GRID
   ============================================ */

.stats-grid {
    display: grid;
    /* Mobile: 1 column */
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

/* Tablet: 2 columns */
@media (min-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop: 3 columns */
@media (min-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.stat-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: var(--spacing-lg);
    text-align: center;
}

.stat-card .value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--spacing-sm);
    line-height: 1;
}

.stat-card .label {
    color: #666;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   GRID SYSTEM - MOBILE FIRST
   ============================================ */

.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 calc(-1 * var(--spacing-xs));
}

.col,
.col-6,
.col-4,
.col-3 {
    /* Mobile: full width */
    flex: 0 0 100%;
    max-width: 100%;
    padding: 0 var(--spacing-xs);
}

/* Tablet and up: enable columns */
@media (min-width: 600px) {
    .col-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    .col-4 {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }
    
    .col-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }
    
    .col {
        flex: 1;
    }
}

/* ============================================
   NAVBAR - MOBILE FRIENDLY
   ============================================ */

.navbar {
    background: var(--dark);
    color: white;
    padding: var(--spacing-md) 0;
    margin-bottom: var(--spacing-lg);
}

.navbar .container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    align-items: stretch;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    text-decoration: none;
    text-align: center;
    padding: var(--spacing-xs) 0;
}

.navbar-nav {
    display: flex;
    flex-direction: column;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 0;
}

.navbar-nav a {
    color: white;
    text-decoration: none;
    padding: var(--spacing-md);
    border-radius: 4px;
    transition: background 0.2s;
    /* Touch-friendly */
    min-height: var(--min-tap-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.navbar-nav a:hover,
.navbar-nav a:active {
    background: rgba(255,255,255,0.1);
}

/* Desktop: horizontal navbar */
@media (min-width: 768px) {
    .navbar .container {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .navbar-brand {
        font-size: 1.5rem;
    }
    
    .navbar-nav {
        flex-direction: row;
        gap: var(--spacing-sm);
    }
    
    .navbar-nav a {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* ============================================
   PROGRESS INDICATOR (for long forms)
   ============================================ */

.form-progress {
    background: white;
    border-radius: 6px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.form-progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: var(--spacing-xs);
}

.form-progress-fill {
    height: 100%;
    background: var(--success);
    transition: width 0.3s ease;
}

.form-progress-text {
    font-size: 0.875rem;
    color: #666;
    text-align: center;
}

/* ============================================
   STICKY SUBMIT BUTTON (mobile)
   ============================================ */

.sticky-submit {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: var(--spacing-md);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    display: none; /* Show via JS when scrolling */
}

@media (max-width: 767px) {
    .sticky-submit.visible {
        display: block;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

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

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--spacing-xs) !important; }
.mb-2 { margin-bottom: var(--spacing-sm) !important; }
.mb-3 { margin-bottom: var(--spacing-md) !important; }
.mb-4 { margin-bottom: var(--spacing-lg) !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--spacing-xs) !important; }
.mt-2 { margin-top: var(--spacing-sm) !important; }
.mt-3 { margin-top: var(--spacing-md) !important; }
.mt-4 { margin-top: var(--spacing-lg) !important; }

.d-none { display: none !important; }
.d-block { display: block !important; }

@media (min-width: 768px) {
    .d-md-none { display: none !important; }
    .d-md-block { display: block !important; }
}

/* ============================================
   RESPONSIVE IMAGES
   ============================================ */

img {
    max-width: 100%;
    height: auto;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus indicators for keyboard navigation */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* ============================================
   LOADING STATES
   ============================================ */

.btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid white;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner 0.6s linear infinite;
}

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

/* ============================================
   SAFE AREA INSETS (for notched phones)
   ============================================ */

@supports (padding: env(safe-area-inset-left)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .sticky-submit {
        padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom));
        padding-left: calc(var(--spacing-md) + env(safe-area-inset-left));
        padding-right: calc(var(--spacing-md) + env(safe-area-inset-right));
    }
}
