/* FamilyVault v1.0.0 - Glassmorphism + Yellow Scheme */
:root {
    --primary: #F59E0B;
    --primary-dark: #D97706;
    --primary-light: #FBBF24;
    --danger: #EF4444;
    --success: #10B981;
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-blur: blur(12px);
    --text: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --radius: 16px;
    --radius-sm: 8px;
    --sidebar-width: 240px;
    --sidebar-collapsed: 60px;
    --bp-sm: 480px;
    --bp-md: 768px;
    --bp-lg: 1024px;
    --bp-xl: 1280px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.5;
}

/* App Layout */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

/* Topbar */
.topbar {
    display: none;
    align-items: center;
    padding: 12px 16px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-title { font-weight: 600; flex: 1; text-align: center; }
.hamburger { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; }
.topbar-user { font-size: 14px; }

/* Sidebar */
.sidebar {
    grid-row: 1 / -1;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--glass-border);
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 200;
}
.sidebar-brand {
    padding: 0 20px 24px;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 16px;
}
.sidebar-nav { list-style: none; flex: 1; }
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.sidebar-nav li a svg { flex-shrink: 0; width: 20px; height: 20px; }
.sidebar-nav li a:hover {
    color: var(--text);
    background: rgba(245, 158, 11, 0.1);
}
.sidebar-nav li.active a {
    color: var(--primary);
    border-left-color: var(--primary);
    background: rgba(245, 158, 11, 0.1);
}
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}
.sidebar-footer a { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.sidebar-footer a:hover { color: var(--danger); }
.sidebar-footer span { display: inline-flex; align-items: center; gap: 4px; }
.sidebar-footer svg { width: 16px; height: 16px; }

/* Content */
.content {
    padding: 32px;
    max-width: 1200px;
    width: 100%;
}

/* Bottom Nav (mobile) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--glass-border);
    padding: 8px 0;
    z-index: 100;
    justify-content: space-around;
}
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 16px;
    text-decoration: none;
    color: var(--text-muted);
    transition: color 0.2s;
}
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a.active { color: var(--primary); }

/* Glass Card */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}
.stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Document Grid */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.doc-card {
    text-decoration: none;
    color: var(--text);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    height: 100%;
}
.doc-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(245, 158, 11, 0.15);
}
.doc-thumb { height: 140px; overflow: hidden; border-radius: var(--radius-sm); margin-bottom: 12px; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.2); }
.doc-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.doc-thumb-icon { font-size: 48px; }
.doc-card-info { display: flex; flex-direction: column; gap: 4px; font-size: 13px; flex: 1; }
.doc-card-cat { color: var(--primary-light); }
.doc-card-name { font-weight: 500; }
.doc-card-date { color: var(--text-muted); font-size: 12px; }
.doc-card-actions { display: flex; gap: 8px; margin-top: 8px; }
.doc-card-actions a, .doc-card-actions button { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; color: #fff; text-decoration: none; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; }

/* Member Grid */
.member-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.member-card {
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.2s;
}
.member-card:hover { transform: translateY(-2px); }
.member-avatar { font-size: 48px; margin-bottom: 12px; }
.member-card h3 { font-size: 16px; margin-bottom: 4px; }
.member-card .text-muted { margin-bottom: 8px; }

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.category-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 16px 12px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}
.category-card:hover { border-color: var(--primary); background: rgba(245, 158, 11, 0.1); }
.category-icon { font-size: 24px; display: block; margin-bottom: 6px; }
.category-name { font-size: 11px; display: block; }
.category-count { font-size: 11px; color: var(--text-muted); }

/* Page Header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h1 { font-size: 24px; }

/* Filters */
.filters form { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-muted); }
input[type="text"], input[type="password"], input[type="email"], select, textarea {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    transition: border-color 0.2s;
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-text-fill-color: #ffffff !important;
    -webkit-box-shadow: 0 0 0 1000px #1a1a2e inset !important;
    caret-color: #ffffff;
    transition: background-color 5000s ease-in-out 0s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}
select { cursor: pointer; padding-right: 36px; appearance: none; -webkit-appearance: none; 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='%23ffffff' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
select option { background: #1a1a2e; color: var(--text); }
select optgroup { background: #1a1a2e; color: var(--primary); font-weight: 700; }
.searchable-select { position: relative; }
.ss-display { padding: 12px 36px 12px 16px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); color: var(--text); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; 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='%23ffffff' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.ss-dropdown { display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 500; background: #1a1a2e; border: 1px solid var(--glass-border); border-radius: var(--radius-sm); margin-top: 4px; max-height: 280px; overflow: hidden; flex-direction: column; }
.searchable-select.open .ss-dropdown { display: flex; }
.ss-search { width: 100%; padding: 10px 12px; border: none; border-bottom: 1px solid var(--glass-border); background: rgba(255,255,255,0.05); color: var(--text); font-size: 14px; outline: none; }
.ss-list { overflow-y: auto; max-height: 230px; }
.ss-group { padding: 8px 12px 4px; font-size: 11px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.5px; }
.ss-item { padding: 8px 12px; cursor: pointer; color: var(--text); }
.ss-item:hover, .ss-item.selected { background: rgba(255,255,255,0.1); }
.ss-empty { padding: 12px; color: var(--text-muted); text-align: center; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 16px rgba(245, 158, 11, 0.3); }
.btn-secondary { background: var(--glass-bg); color: var(--text); border: 1px solid var(--glass-border); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-danger { background: #F87171; color: #fff; }
.btn-danger:hover { background: #EF4444; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-back { margin-bottom: 16px; display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); text-decoration: none; font-size: 14px; }
.btn-back:hover { color: var(--primary); }
.btn-sm { padding: 6px; font-size: 18px; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; }
/* Visible "chip" fill for icon-only actions (copy, view…) — leaves .btn-danger/.btn-primary untouched */
.btn-sm:not(.btn-primary):not(.btn-danger):not(.btn-secondary) {
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: var(--text);
}
.btn-sm:not(.btn-primary):not(.btn-danger):not(.btn-secondary):hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: var(--primary);
    color: var(--primary);
}

/* Badges */
.badge { padding: 2px 8px; border-radius: 12px; font-size: 13px; }
.badge-green { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.badge-red { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.badge-yellow { background: rgba(245, 158, 11, 0.2); color: var(--primary); }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.3); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--glass-border); font-size: 14px; }
.data-table th { color: var(--text-muted); font-weight: 500; }
.log-table td { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace; font-size: 12px; }
.detail-table td { padding: 8px 12px; }
.detail-table td:first-child { color: var(--text-muted); width: 120px; }

/* Health */
.health-overall { font-size: 18px; margin-bottom: 24px; }
.health-table { width: 100%; }
.health-table td { padding: 8px 12px; }
.health-table td:first-child { width: 30px; }
.health-table td:nth-child(2) { width: 25%; }
.health-table td:nth-child(3) { width: 75%; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--glass-border); padding-bottom: 0; }
.tab { padding: 10px 20px; text-decoration: none; color: var(--text-muted); border-bottom: 2px solid transparent; transition: all 0.2s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Activity List */
.activity-list { list-style: none; }
.activity-list li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--glass-border); font-size: 14px; align-items: center; }
.activity-list li:last-child { border-bottom: none; }
.activity-action { font-weight: 500; min-width: 100px; }
.activity-detail { flex: 1; color: var(--text-muted); }
.activity-time { font-size: 12px; color: var(--text-muted); }

/* Share List */
.share-list { display: flex; flex-direction: column; gap: 12px; }
.share-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.03); flex-wrap: wrap; gap: 8px; }
.share-item.expired { opacity: 0.6; }
.share-info { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.share-actions { display: flex; align-items: center; gap: 8px; }
.share-url { font-size: 12px; background: rgba(0,0,0,0.3); padding: 4px 8px; border-radius: 4px; }

/* Modal */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000; align-items: center; justify-content: center; padding: 16px; }
.modal.open { display: flex; }
.modal-content { width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header button { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--glass-border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    margin-bottom: 16px;
    position: relative;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background: rgba(245, 158, 11, 0.05); }
.drop-zone:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2); }
.drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.preview-wrap { position: relative; display: inline-block; }
.btn-clear-preview { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.5); border: none; border-radius: 50%; width: 64px; height: 64px; font-size: 32px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff; }
.btn-clear-preview:hover { background: rgba(239,68,68,0.8); }

/* Upload Progress */
.upload-progress { margin-top: 12px; }
.progress-bar { height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.3s; }

/* Pagination */
.pagination { display: flex; gap: 4px; margin-top: 24px; justify-content: center; }
.pagination a { padding: 8px 14px; border-radius: var(--radius-sm); text-decoration: none; color: var(--text-muted); background: var(--glass-bg); border: 1px solid var(--glass-border); }
.pagination a.active { background: var(--primary); color: #000; border-color: var(--primary); }

/* Document Detail */
.doc-detail { display: grid; gap: 16px; }
.doc-preview img, .doc-preview iframe { width: 100%; border-radius: var(--radius-sm); }
.doc-actions { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

/* Member Profile */
.member-profile { text-align: center; padding: 32px; margin-bottom: 24px; }
.member-profile .member-avatar { font-size: 64px; }

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.login-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-brand { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 24px; }
.login-card .form-group { text-align: left; }

/* Share Page */
.share-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.share-card { width: 100%; max-width: 700px; text-align: center; }
.share-brand { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.share-preview { margin: 20px 0; }
.share-preview img { max-width: 100%; border-radius: var(--radius-sm); }
.share-preview iframe { width: 100%; border: none; border-radius: var(--radius-sm); }
.share-meta { text-align: left; margin: 16px 0; }
.share-meta p { padding: 6px 0; font-size: 14px; }
.share-notice { color: var(--primary); font-weight: 500; margin-top: 16px; }
.share-footer { color: var(--text-muted); font-size: 12px; margin-top: 16px; }

/* Password toggle */
.input-password { position: relative; }
.input-password input { padding-right: 44px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; padding: 4px 8px; display: inline-flex; align-items: center; }
.password-toggle:hover { color: var(--text); }

/* Avatar */
.clickable-avatar { cursor: pointer; position: relative; transition: transform 0.2s; display: inline-block; }
.clickable-avatar:hover { transform: scale(1.05); }
.clickable-avatar::after { content: ''; position: absolute; bottom: 2px; right: 2px; width: 36px; height: 36px; opacity: 0; transition: opacity 0.2s; background: rgba(0,0,0,0.5) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 16C13.6569 16 15 14.6569 15 13C15 11.3431 13.6569 10 12 10C10.3431 10 9 11.3431 9 13C9 14.6569 10.3431 16 12 16Z'/%3E%3Cpath d='M3 16.8V9.2C3 8.0799 3 7.51984 3.21799 7.09202C3.40973 6.71569 3.71569 6.40973 4.09202 6.21799C4.51984 6 5.0799 6 6.2 6H7.25464C7.37758 6 7.43905 6 7.49576 5.9935C7.79166 5.95961 8.05705 5.79559 8.21969 5.54609C8.25086 5.49827 8.27836 5.44328 8.33333 5.33333C8.44329 5.11342 8.49827 5.00346 8.56062 4.90782C8.8859 4.40882 9.41668 4.08078 10.0085 4.01299C10.1219 4 10.2448 4 10.4907 4H13.5093C13.7552 4 13.8781 4 13.9915 4.01299C14.5833 4.08078 15.1141 4.40882 15.4394 4.90782C15.5017 5.00345 15.5567 5.11345 15.6667 5.33333C15.7216 5.44329 15.7491 5.49827 15.7803 5.54609C15.943 5.79559 16.2083 5.95961 16.5042 5.9935C16.561 6 16.6224 6 16.7454 6H17.8C18.9201 6 19.4802 6 19.908 6.21799C20.2843 6.40973 20.5903 6.71569 20.782 7.09202C21 7.51984 21 8.0799 21 9.2V16.8C21 17.9201 21 18.4802 20.782 18.908C20.5903 19.2843 20.2843 19.5903 19.908 19.782C19.4802 20 18.9201 20 17.8 20H6.2C5.0799 20 4.51984 20 4.09202 19.782C3.71569 19.5903 3.40973 19.2843 3.21799 18.908C3 18.4802 3 17.9201 3 16.8Z'/%3E%3C/svg%3E") no-repeat center; border-radius: 50%; padding: 2px; }
.clickable-avatar:hover::after { opacity: 1; }
.avatar-img { width: 128px; height: 128px; border-radius: 50%; object-fit: cover; display: block; border: 2px solid rgba(59, 130, 246, 0.5); }
.avatar-img.female { border-color: rgba(236, 72, 153, 0.5); }
.member-profile .avatar-img { width: 192px; height: 192px; }
.member-card .avatar-img { width: 128px; height: 128px; }
.avatar-default-male { background: rgba(59, 130, 246, 0.25); border: 2px solid rgba(59, 130, 246, 0.5); border-radius: 50%; width: 128px; height: 128px; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.avatar-default-female { background: rgba(236, 72, 153, 0.25); border: 2px solid rgba(236, 72, 153, 0.5); border-radius: 50%; width: 128px; height: 128px; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.member-profile .avatar-default-male, .member-profile .avatar-default-female { width: 192px; height: 192px; font-size: 72px; }
.member-avatar { font-size: 48px; margin-bottom: 12px; line-height: 1; }

/* Crop */
.crop-container { position: relative; width: 100%; height: 300px; overflow: hidden; border-radius: var(--radius-sm); background: #000; display: flex; align-items: center; justify-content: center; }
.crop-container canvas { max-width: 100%; max-height: 100%; }
#cropCanvas { cursor: move; }

/* Utilities */
.text-muted { color: rgba(255, 255, 255, 0.7); }
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-capitalize { text-transform: capitalize; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.hidden { display: none; }
.alert-success { background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.3); }
.install-card { max-width: 500px; }
.install-note { margin-top: 16px; font-size: 14px; color: rgba(255, 255, 255, 0.7); }
.form-section-title { margin: 16px 0 8px; }
.crop-hint { text-align: center; margin-top: 8px; }

/* Toast notifications */
.toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 9999; pointer-events: none; }
.toast { background: var(--glass-bg); backdrop-filter: var(--glass-blur); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 12px 24px; color: var(--text); font-size: 14px; margin-bottom: 8px; pointer-events: auto; animation: toastIn 0.4s ease, toastOut 0.4s ease 3s forwards; opacity: 0; }
.toast.success { border-color: rgba(16, 185, 129, 0.5); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); }
@keyframes toastIn { 0% { opacity: 0; transform: translateX(100px); } 100% { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { 0% { opacity: 1; transform: translateX(0); } 100% { opacity: 0; transform: translateX(-100px); } }

/* Dialog modal */
.dialog-message { margin-bottom: 16px; font-size: 14px; color: var(--text-muted); }
.dialog-input { width: 100%; padding: 10px 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); color: var(--text); font-size: 14px; margin-top: 4px; }

/* Accessibility */
.skip-link { position: absolute; top: -40px; left: 0; background: var(--primary); color: #000; padding: 8px 16px; z-index: 9999; font-weight: 600; }
.skip-link:focus { top: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
a:focus-visible, .btn:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.modal[aria-modal] { }
h1 { font-size: 24px; margin-bottom: 16px; }
h2 { font-size: 18px; margin: 24px 0 12px; }
h3 { font-size: 16px; margin-bottom: 12px; }

/* Responsive: Tablet (768px - 1023px) */
@media (max-width: 1023px) {
    .app { grid-template-columns: var(--sidebar-collapsed) 1fr; }
    .sidebar { width: var(--sidebar-collapsed); }
    .sidebar-brand, .sidebar-nav span, .sidebar-footer span { display: none; }
    .sidebar-nav li a { justify-content: center; padding: 14px; }
    .sidebar-footer { justify-content: center; }
    .sidebar-footer a { font-size: 18px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .doc-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
    .content { padding: 24px; }
    .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .share-item { flex-wrap: wrap; }
    .share-url { font-size: 11px; }
    .tab { padding: 8px 14px; font-size: 13px; }
}

/* Responsive: Mobile (≤767px) */
@media (max-width: 767px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
    .topbar { display: flex; }
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: 280px;
        height: 100vh;
        transition: left 0.3s;
        z-index: 300;
    }
    .sidebar.open { left: 0; }
    .sidebar-brand, .sidebar-nav span, .sidebar-footer span { display: block; }
    .sidebar-nav li a { justify-content: flex-start; }
    .sidebar-footer { justify-content: space-between; padding: 16px 20px; }
    .sidebar-footer a { font-size: 14px; }
    .bottom-nav { display: flex; }
    .content { padding: 16px; padding-bottom: 80px; overflow-x: hidden; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .doc-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .member-grid { grid-template-columns: repeat(2, 1fr); }
    .category-grid { grid-template-columns: repeat(3, 1fr); }
    .filters form { flex-direction: column; }
    .filters form input, .filters form select { width: 100%; }
    .page-header { flex-direction: column; gap: 12px; align-items: flex-start; }
    .modal-content { max-width: 100%; max-height: 100vh; border-radius: 0; }
    .tabs { overflow-x: auto; }
    .share-item { flex-direction: column; align-items: flex-start; }
    .doc-actions { flex-direction: column; }
    .doc-actions .btn { width: 100%; justify-content: center; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: unset; width: 36px; height: 36px; }
    .pagination a { min-height: 44px; min-width: 44px; display: flex; align-items: center; justify-content: center; }
    input, select { min-height: 48px; }
    .health-table td:nth-child(2) { width: auto; }
    .health-table td:nth-child(3) { width: auto; }
    .health-table td { display: block; padding: 4px 12px; }
    .health-table tr { display: flex; flex-wrap: wrap; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--glass-border); }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 6px; white-space: nowrap; }
    .glass-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .share-url { word-break: break-all; }
    .share-actions { width: 100%; }
    .tab { padding: 8px 12px; font-size: 13px; }
}

/* Responsive: Small phone (≤480px) */
@media (max-width: 480px) {
    .content { padding: 12px; padding-bottom: 80px; }
    .doc-grid { grid-template-columns: 1fr; }
    .category-grid { grid-template-columns: repeat(2, 1fr); }
    .member-grid { grid-template-columns: 1fr; }
    .stats-grid { gap: 8px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 250;
}
.sidebar-overlay.open { display: block; }

/* Watermark "Generate" previews */
.wm-previews { display: flex; gap: 1rem; flex-wrap: wrap; margin: 0.25rem 0 1rem; }
.wm-preview-col { flex: 1 1 160px; min-width: 140px; }
.wm-preview-label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.wm-preview {
    position: relative; height: 180px; border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm); overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.18);
}
.wm-preview img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.wm-preview img[hidden] { display: none; } /* keep the <img> hidden (no broken icon) until a src loads */
.wm-preview-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 0.5rem; }
/* Checkerboard so the faint, semi-transparent stamp is visible */
.wm-preview.stamp {
    background-color: #ffffff;
    background-image:
        linear-gradient(45deg, #cfcfcf 25%, transparent 25%),
        linear-gradient(-45deg, #cfcfcf 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #cfcfcf 75%),
        linear-gradient(-45deg, transparent 75%, #cfcfcf 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.wm-preview.stamp .wm-preview-empty { color: #555; }
