/* ==========================================================================
   app.css — Theme, Typography, Layout, and Base Styles
   Property Management CRM
   ========================================================================== */

/* --- CSS Custom Properties (Theming) --- */
:root {
    /* Branding colors (overridden inline by PHP branding config) */
    --primary-color: #1a73e8;
    --secondary-color: #34495e;
    --accent-color: #e74c3c;

    /* Derived colors */
    --primary-light: color-mix(in srgb, var(--primary-color) 15%, #fff);
    --primary-dark: color-mix(in srgb, var(--primary-color) 85%, #000);
    --secondary-light: color-mix(in srgb, var(--secondary-color) 15%, #fff);
    --accent-light: color-mix(in srgb, var(--accent-color) 15%, #fff);

    /* Neutral palette */
    --bg-color: #f5f7fa;
    --bg-white: #ffffff;
    --text-color: #2c3e50;
    --text-muted: #7f8c8d;
    --text-light: #95a5a6;
    --border-color: #e1e8ed;
    --border-light: #f0f3f5;

    /* Sidebar */
    --sidebar-bg: var(--secondary-color);
    --sidebar-text: #ecf0f1;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(255, 255, 255, 0.15);
    --sidebar-width: 260px;

    /* Topbar */
    --topbar-height: 60px;
    --topbar-bg: var(--bg-white);
    --topbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.16);

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --line-height-tight: 1.25;
    --line-height-base: 1.5;
    --line-height-relaxed: 1.75;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;

    /* Z-index layers */
    --z-sidebar: 100;
    --z-topbar: 90;
    --z-overlay: 200;
    --z-modal: 300;
    --z-toast: 400;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--text-color);
    background-color: var(--bg-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

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

h1, h2, h3, h4, h5, h6 {
    line-height: var(--line-height-tight);
    font-weight: 600;
    color: var(--text-color);
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }

p {
    margin-bottom: var(--spacing-md);
}

/* --- App Layout --- */
.app-body {
    min-height: 100vh;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform var(--transition-base);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-lg) var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.sidebar-logo-placeholder {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-lg);
}

.sidebar-brand {
    font-size: var(--font-size-lg);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1;
    padding: var(--spacing-sm) 0;
}

.sidebar-menu {
    list-style: none;
}

.sidebar-menu-item {
    margin: 2px var(--spacing-sm);
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--sidebar-text);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
    font-size: var(--font-size-sm);
}

.sidebar-menu-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-menu-item.active .sidebar-menu-link {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

.sidebar-menu-icon {
    width: 20px;
    text-align: center;
    font-size: var(--font-size-base);
    opacity: 0.8;
}

.sidebar-menu-item.active .sidebar-menu-icon {
    opacity: 1;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-sidebar) - 1);
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Topbar --- */
.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--topbar-bg);
    box-shadow: var(--topbar-shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    z-index: var(--z-topbar);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    color: var(--text-color);
    cursor: pointer;
    padding: var(--spacing-sm);
}

.topbar-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.topbar-user-avatar {
    font-size: var(--font-size-2xl);
    color: var(--text-muted);
}

.topbar-user-info {
    display: flex;
    flex-direction: column;
    line-height: var(--line-height-tight);
}

.topbar-user-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
}

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

.topbar-logout {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.topbar-logout:hover {
    color: var(--accent-color);
    background: var(--accent-light);
}

/* --- Content Area --- */
.content-area {
    flex: 1;
    padding: var(--spacing-lg);
}

/* --- Alerts --- */
.alert {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-sm);
    border: 1px solid transparent;
}

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

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

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

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border-color: #ffeeba;
}

/* --- Auth Layout --- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
}

.auth-wrapper {
    width: 100%;
    max-width: 420px;
    padding: var(--spacing-lg);
}

.auth-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-xl);
}

.auth-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.auth-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin: 0 auto var(--spacing-md);
    border-radius: var(--radius-md);
}

.auth-logo-placeholder {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--spacing-md);
    background: var(--primary-light);
    color: var(--primary-color);
    border-radius: var(--radius-md);
    font-size: var(--font-size-3xl);
}

.auth-company-name {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--secondary-color);
}

.auth-footer {
    text-align: center;
    margin-top: var(--spacing-lg);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* --- Utility Classes --- */
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary-color); }
.text-danger { color: var(--accent-color); }
.text-success { color: #27ae60; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.font-bold { font-weight: 700; }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.hidden { display: none !important; }
