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

:root {
    --bg: #f5f5f5;
    --surface: #fff;
    --primary: #1a56db;
    --primary-hover: #1647b8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warning: #f59e0b;
    --text: #1f2937;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e7eb;
    --border-focus: #1a56db;
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === LAYOUT === */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 52px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
}

nav .brand {
    font-weight: 600;
    font-size: 16px;
    color: var(--primary);
    margin-right: 16px;
    white-space: nowrap;
}

nav a.nav-link {
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: all 0.15s;
    white-space: nowrap;
}

nav a.nav-link:hover, nav a.nav-link.active {
    color: var(--primary);
    background: #eff6ff;
    text-decoration: none;
}

.nav-right { margin-left: auto; display: flex; gap: 4px; align-items: center; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
}

@media (max-width: 768px) {
    nav { padding: 0 12px; height: auto; min-height: 44px; }
    nav .brand { font-size: 14px; }
    nav a.nav-link { font-size: 12px; padding: 4px 8px; }
    .container { padding: 16px 8px; }
}

/* === CARDS === */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.card-header h2 { font-size: 16px; font-weight: 600; }

.card-header h3 { font-size: 14px; font-weight: 600; }

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; }

/* === FORMS === */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }

/* === TABLES === */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; background: #fafbfc; }
tr:hover td { background: #f9fafb; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* === BADGES === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 100px;
    white-space: nowrap;
}
.badge-gray { background: #f3f4f6; color: #6b7280; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-orange { background: #fff7ed; color: #c2410c; }

/* === ALERTS === */
.flash { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.flash.error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* === SEARCH BAR === */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar input, .search-bar select {
    padding: 7px 12px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.search-bar input { min-width: 200px; flex: 1; }
.search-bar input:focus, .search-bar select:focus {
    outline: none;
    border-color: var(--border-focus);
}

/* === REMINDER BOX === */
.reminder-box {
    border-left: 3px solid var(--danger);
    padding: 12px 16px;
    margin-bottom: 12px;
    background: #fef2f2;
    border-radius: 0 var(--radius) var(--radius) 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.reminder-box.warn { border-color: var(--warning); background: #fffbeb; }
.reminder-box.info { border-color: var(--primary); background: #eff6ff; }

.reminder-box .main { font-size: 13px; }
.reminder-box .sub { font-size: 12px; color: var(--text-muted); }

/* === LOGIN PAGE === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 24px; text-align: center; }

/* === DASHBOARD GRID === */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.stat-card .number { font-size: 32px; font-weight: 700; }
.stat-card .label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.stat-card .number.danger { color: var(--danger); }
.stat-card .number.warn { color: var(--warning); }
.stat-card .number.success { color: var(--success); }

/* === TREE === */
.dept-tree { font-size: 13px; }
.dept-tree ul { list-style: none; padding-left: 20px; }
.dept-tree li { padding: 3px 0; }
.dept-tree .dept-name { color: var(--text); }

/* === MODAL === */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-box h3 { font-size: 16px; margin-bottom: 16px; }

/* === DETAIL ROW === */
.detail-row { display: flex; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.detail-label { color: var(--text-muted); min-width: 80px; flex-shrink: 0; }

/* === EMPTY STATE === */
.empty { text-align: center; padding: 40px 20px; color: var(--text-light); font-size: 13px; }

/* === ACTIONS === */
.actions { display: flex; gap: 4px; }
.inline-form { display: inline; }
.separator { color: var(--border); margin: 0 4px; }

/* === MOBILE TABLE === */
@media (max-width: 640px) {
    th, td { padding: 8px 6px; font-size: 12px; }
    .hide-mobile { display: none; }
    .dashboard-grid { grid-template-columns: 1fr; }
    /* mobile-first form improvements */
    .form-row { flex-direction: column; }
    .form-row .form-group { min-width: 100%; }
}

/* === SHARED COMPONENTS === */
/* star rating (used in orgs, contacts, projects lists + detail pages) */
.star-group { display: inline-flex; gap: 1px; cursor: pointer; }
.star-group .s { color: #d1d5db; font-size: 14px; transition: color 0.1s; }
.star-group .s.on { color: #f59e0b; }

/* department tree (used in departments.html + organization_detail.html) */
.dept-tree { font-size: 13px; }
.dept-tree ul { list-style: none; padding-left: 24px; border-left: 1px dashed var(--border); margin-left: 8px; }
.dept-tree li { padding: 4px 0; }
.dept-row { display: inline-flex; align-items: center; gap: 6px; }
.dept-row .name { font-weight: 500; }
.dept-row .level-badge { font-size: 10px; color: var(--text-muted); }
.level-1 .name { color: var(--primary); font-weight: 600; }
.level-2 .name { color: var(--text); }
.level-3 .name { color: var(--text-muted); }

/* org name ellipsis in table cells */
.td-org-name { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }

/* action buttons row */
.td-actions-row { display: flex; gap: 4px; flex-wrap: nowrap; }
