/* 
 * main.css
 * Global styles, variables, and layout.
 */

:root {
    /* Brand Colors - Construction Theme */
    --color-primary: #FFD700;
    /* Safety Yellow */
    --color-primary-dark: #F4C430;
    --color-secondary: #333333;
    /* Dark Grey */
    --color-accent: #0056b3;
    /* Blue for links/actions */

    /* UI Colors */
    --color-bg: #f4f6f8;
    --color-surface: #ffffff;
    --color-text: #212b36;
    --color-text-secondary: #637381;
    --color-border: #dfe3e8;
    --color-success: #4caf50;
    --color-warning: #ff9800;
    --color-error: #f44336;

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

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-base: 16px;
    --font-size-sm: 14px;
    --font-size-lg: 18px;
    --font-size-h1: 24px;
    --font-size-h2: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    /* Dark Mode Variables */
    --color-bg-dark: #1a1a1a;
    --color-surface-dark: #2d2d2d;
    --color-text-dark: #e0e0e0;
    --color-text-secondary-dark: #a0a0a0;
    --color-border-dark: #404040;
}

/* Dark Mode — override CSS variables so all var() references update automatically */
body.dark-mode {
    --color-bg:             #111827;
    --color-surface:        #1f2937;
    --color-text:           #f3f4f6;
    --color-text-secondary: #9ca3af;
    --color-border:         #374151;
    --color-accent:         #60a5fa;
    background-color: var(--color-bg);
    color: var(--color-text);
}

/* Surfaces with hardcoded background-color */
body.dark-mode .card,
body.dark-mode .topbar,
body.dark-mode .login-card {
    background-color: var(--color-surface);
}

body.dark-mode .card {
    border: 1px solid var(--color-border);
    box-shadow: none;
}

body.dark-mode .topbar {
    border-bottom-color: var(--color-border);
}

/* Form inputs */
body.dark-mode .form-input {
    background-color: var(--color-bg);
    border-color: var(--color-border);
    color: var(--color-text);
}

body.dark-mode .form-input::placeholder {
    color: var(--color-text-secondary);
}

body.dark-mode select.form-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Search bar */
body.dark-mode .search-input {
    background-color: var(--color-bg);
    border-color: var(--color-border);
    color: var(--color-text);
}

/* Table headers — hardcoded #f9f9f9 */
body.dark-mode thead {
    background-color: var(--color-surface) !important;
    color: var(--color-text-secondary);
}

body.dark-mode tr {
    border-color: var(--color-border) !important;
}

/* Inline style overrides — #f9f9f9 used in filter bars, table heads, demo box */
body.dark-mode [style*="background: #f9f9f9"],
body.dark-mode [style*="background-color: #f9f9f9"] {
    background-color: var(--color-surface) !important;
    color: var(--color-text-secondary) !important;
}

/* Inline style overrides — #eee used in cancel buttons, category pills, skills badges */
body.dark-mode [style*="background: #eee"],
body.dark-mode [style*="background-color: #eee"],
body.dark-mode [style*="background:#eee"] {
    background-color: #374151 !important;
    color: var(--color-text) !important;
}

/* Inline rgba(0,0,0,0.05) hover tints */
body.dark-mode [style*="background: rgba(0, 0, 0, 0.05)"] {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

/* Modals */
body.dark-mode .modal-content {
    background-color: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
}

/* Notification dropdown */
body.dark-mode #notif-dropdown {
    background-color: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
}

/* Nav links — cascade from variable already handles text color */
body.dark-mode .nav-link {
    color: var(--color-text-secondary);
}

body.dark-mode .nav-link:hover,
body.dark-mode .nav-link.active {
    color: var(--color-primary);
}

/* Form labels */
body.dark-mode .form-label {
    color: var(--color-text);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text);
    font-size: var(--font-size-base);
    line-height: 1.5;
    height: 100vh;
    height: 100dvh; /* dynamic viewport height — fixes iOS Safari bottom-bar clipping */
    overflow: hidden;
    /* App-like feel */
    transition: background-color 0.3s, color 0.3s;
}

/* Layout */
#app {
    height: 100%;
    width: 100%;
}

.app-layout {
    display: flex;
    height: 100%;
}

/* Topbar */
.topbar {
    height: 64px;
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.search-bar {
    position: relative;
    width: 300px;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border-radius: 20px;
    border: 1px solid var(--color-border);
    background-color: var(--color-bg);
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-accent);
    background-color: var(--color-surface);
    width: 320px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
}

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

.action-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    position: relative;
    color: var(--color-text-secondary);
    padding: 10px;
    border-radius: 50%;
    transition: background 0.2s;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--color-text);
}

.badge {
    position: absolute;
    top: 0;
    right: 0;
    background-color: var(--color-error);
    color: white;
    font-size: 10px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Hamburger toggle — hidden on desktop, shown on mobile */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    color: var(--color-text-secondary);
    border-radius: var(--radius-sm);
    transition: background 0.2s;
    flex-shrink: 0;
}

.hamburger-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--color-text);
}

.hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    transition: all 0.3s;
}

/* Sidebar overlay backdrop — covers content when sidebar is open on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active {
    display: block;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--color-secondary);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: background-color 0.3s;
}

.brand {
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background-color: rgba(0, 0, 0, 0.2);
}

.logo-icon {
    width: 32px;
    height: 32px;
    background-color: var(--color-primary);
    color: var(--color-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border-radius: var(--radius-sm);
}

.logo-text {
    font-weight: 700;
    font-size: var(--font-size-lg);
    color: var(--color-primary);
}

.main-nav {
    flex: 1;
    padding: var(--spacing-md) 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    color: #b0b0b0;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    color: var(--color-primary);
    background-color: rgba(255, 215, 0, 0.1);
    border-left-color: var(--color-primary);
}

.nav-link .icon {
    margin-right: var(--spacing-md);
    font-size: 1.2em;
}

.user-mini-profile {
    padding: var(--spacing-md);
    background-color: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: var(--font-size-sm);
    color: #aaa;
}

.btn-icon {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 1.2em;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: #fff;
}

/* Main Content Wrapper */
.content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xl);
    background-color: var(--color-bg);
    transition: background-color 0.3s;
}

/* Utilities */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

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

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

.card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        height: 100%;
        z-index: 100;
        transition: left 0.3s;
        padding-top: env(safe-area-inset-top, 0px);
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        padding: var(--spacing-md);
        padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
    }

    .topbar {
        padding-top: env(safe-area-inset-top, 0px);
        height: calc(64px + env(safe-area-inset-top, 0px));
    }

    .hamburger-btn {
        display: flex;
    }

    .search-bar {
        display: none;
    }
}
