:root {
    /* Colors mapping from main CRM */
    --primary: #A35139;
    --primary-hover: #8C442E;
    --secondary: #2C3B4D;
    --success: #2D6B5E;
    --danger: #A82525;
    --warning: #FFB162;
    --info: #1B2632;
    
    --bg-app: #f4f4f6; /* iOS style light gray background */
    --bg-surface: #ffffff;
    
    --text-main: #1c1c1e;
    --text-secondary: #3a3a3c;
    --text-muted: #8e8e93;
    
    --border: #e5e5ea;
    
    /* Mobile specific metrics */
    --header-height: 50px;
    --bottom-nav-height: 60px;
    /* iOS Safe area variables */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden; /* App-like behavior */
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
}

/* Utilities */
.hidden { display: none !important; }
.mt-4 { margin-top: 1rem; }
.text-primary { color: var(--primary) !important; }

/* Typography */
h1, h2, h3 { font-weight: 600; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:active { opacity: 0.7; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--border); color: var(--text-main); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-block { width: 100%; }
.btn-large { padding: 1rem; font-size: 1.1rem; }
.btn-text { background: transparent; border: none; font-size: 1rem; font-weight: 600; }
.icon-btn { background: transparent; border: none; font-size: 1.25rem; color: var(--text-secondary); cursor: pointer; padding: 0.5rem; }

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

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

.form-control {
    width: 100%;
    padding: 0.4rem;
    font-size: 16px; /* Must remain 16px to prevent iOS Safari zoom */
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-surface);
    color: var(--text-main);
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

select.form-control {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%238e8e93%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem top 50%;
    background-size: 0.65rem auto;
}

/* Fullscreen Views (Login / App) */
.fullscreen-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
}

.login-container {
    padding: 2rem;
    margin: auto;
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 3rem;
}

.login-logo h1 { font-size: 2rem; color: var(--secondary); margin-bottom: 0.5rem; }
.login-logo p { color: var(--text-muted); }

/* Main App Layout */
#mainApp {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
}

.app-header {
    height: calc(var(--header-height) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 1rem;
    padding-right: 0.5rem;
    flex-shrink: 0;
    z-index: 10;
}

.header-brand {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 80px); /* Space for FAB */
}

/* Views inside app content */
.tab-view {
    display: none;
    animation: fadeIn 0.2s ease-out;
}
.tab-view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.view-header {
    padding: 0.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.5rem 0.5rem 2rem;
    font-size: 0.85rem;
    border-radius: 12px;
    border: none;
    background: var(--bg-app) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%238e8e93' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E") no-repeat 0.6rem center;
    outline: none;
}

.card-list {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

/* Cards */
.card {
    background: var(--bg-surface);
    border-radius: 6px;
    padding: 0.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.card:active {
    background: #f9f9f9;
}

.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.card-amount {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.8rem;
}

.badge {
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-novo { background: #FFF5EB; color: #cc8400; }
.badge-andamento { background: #E6F0ED; color: #1a4239; }
.badge-fechado { background: #FCE8E8; color: #7a1b1b; }
.badge-perdido { background: #FCE8E8; color: #7a1b1b; }
.badge-cancelado { background: #FCE8E8; color: #7a1b1b; }

.contact-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
}
.contact-actions a {
    flex: 1;
    text-align: center;
    padding: 0.5rem;
    background: var(--bg-app);
    border-radius: 8px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Floating Action Button */
.fab-btn {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 1rem);
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--primary);
    color: white;
    font-size: 1.5rem;
    border: none;
    box-shadow: 0 4px 12px rgba(163, 81, 57, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    cursor: pointer;
    transition: transform 0.1s;
}
.fab-btn:active { transform: scale(0.95); }

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 30;
}

.nav-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.65rem;
}

.nav-item i { font-size: 1.1rem; }
.nav-item.active { color: var(--primary); font-weight: 600; }

/* Modals (Full Screen iOS Style) */
.mobile-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-app);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.mobile-modal:not(.hidden) {
    transform: translateY(0);
}

.modal-header {
    height: calc(var(--header-height) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 0.5rem;
    padding-right: 1rem;
    flex-shrink: 0;
}

.modal-header h3 { font-size: 1.1rem; flex: 1; text-align: center; }

.modal-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.5rem 1rem;
}

/* Toast */
.toast {
    position: fixed;
    top: calc(1rem + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-main);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    white-space: nowrap;
}
