:root {
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
    --bg: #eef1f6;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 10px 40px rgba(15, 23, 42, 0.08);
    --radius: 14px;
    --sidebar-width: 260px;

    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --accent-strong: #1d4ed8;
}

body.app--admin {
    --accent: #6d28d9;
    --accent-soft: #ede9fe;
    --accent-strong: #5b21b6;
}

body.app--manage {
    --accent: #0d9488;
    --accent-soft: #ccfbf1;
    --accent-strong: #0f766e;
}

body.app--employee {
    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --accent-strong: #1d4ed8;
}

body.app--home {
    --accent: #334155;
    --accent-soft: #f1f5f9;
    --accent-strong: #1e293b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a {
    color: var(--accent-strong);
}

/* —— App shell —— */

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

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    margin-bottom: 28px;
    padding: 4px 8px;
}

.sidebar-brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.sidebar-brand-text {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.sidebar-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    margin: 0 8px 10px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: #cbd5e1;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-nav-item.is-active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.sidebar-nav-icon {
    width: 1.4rem;
    text-align: center;
    opacity: 0.9;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user-name {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
}

.sidebar-user-roles {
    display: block;
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 4px;
    line-height: 1.35;
}

.sidebar-logout {
    display: inline-block;
    margin-top: 12px;
    font-size: 0.85rem;
    color: #94a3b8;
    text-decoration: none;
}

.sidebar-logout:hover {
    color: #fff;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 32px 40px 48px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.85rem;
    letter-spacing: -0.03em;
}

.page-header-subtitle {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 1.05rem;
}

.main-content {
    max-width: 1100px;
}

/* —— Home / area cards —— */

.area-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.area-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.area-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12);
    border-color: var(--accent);
}

.area-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 16px;
}

.area-card--admin .area-card-icon {
    background: #ede9fe;
    color: #6d28d9;
}

.area-card--manage .area-card-icon {
    background: #ccfbf1;
    color: #0d9488;
}

.area-card--employee .area-card-icon {
    background: #dbeafe;
    color: #2563eb;
}

.area-card h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
}

.area-card p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    flex: 1;
}

.area-card-cta {
    margin-top: 18px;
    font-weight: 600;
    color: var(--accent-strong);
    font-size: 0.9rem;
}

/* —— Panels & forms —— */

.panels {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    box-shadow: var(--shadow);
}

.panel h2 {
    margin: 0 0 6px;
    font-size: 1.15rem;
}

.panel-intro {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 0.92rem;
}

label {
    display: block;
    margin: 14px 0 6px;
    font-weight: 600;
    font-size: 0.88rem;
}

label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    margin: 8px 0;
}

label.checkbox-label input {
    width: auto;
    margin: 0;
}

input,
textarea,
select,
button {
    font: inherit;
    padding: 10px 12px;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 4px;
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

button,
.btn {
    background: var(--accent);
    border: 0;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    padding: 11px 18px;
    width: auto;
    display: inline-block;
    text-decoration: none;
    border-radius: 8px;
    margin-top: 8px;
}

button:hover,
.btn:hover {
    background: var(--accent-strong);
    color: #fff;
}

.btn-secondary {
    background: transparent;
    color: var(--accent-strong);
    border: 1px solid var(--border);
    margin-left: 8px;
}

.btn-secondary:hover {
    background: var(--accent-soft);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

/* —— Tables —— */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: 12px 10px;
    text-align: left;
}

th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 700;
}

tr:hover td {
    background: #f8fafc;
}

.app-edit-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-edit-links a {
    display: block;
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
}

.app-edit-links a:hover {
    background: var(--accent-soft);
}

/* —— Alerts —— */

.alert {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-weight: 500;
}

.alert--success {
    background: #ecfdf5;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert--error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* —— Smartphone homescreen (manage / employee) —— */

.homescreen-wrap {
    display: flex;
    justify-content: center;
    padding: 12px 0 40px;
}

.homescreen {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 22px 12px;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

.homescreen-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.12s ease;
}

.homescreen-tile:hover {
    transform: scale(1.04);
}

.homescreen-tile:active {
    transform: scale(0.94);
}

.homescreen-icon {
    --icon-hue: 220;
    width: 72px;
    height: 72px;
    border-radius: 18px;
    overflow: hidden;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.06),
        0 8px 20px rgba(15, 23, 42, 0.14);
    background: hsl(var(--icon-hue) 55% 48%);
}

.homescreen-icon img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.homescreen-icon-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 1.75rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(
        145deg,
        hsl(var(--icon-hue) 62% 52%) 0%,
        hsl(calc(var(--icon-hue) + 24) 58% 40%) 100%
    );
}

.homescreen-label {
    margin-top: 8px;
    max-width: 80px;
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    color: var(--text);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* —— Admin icon upload —— */

.field-hint {
    margin: -4px 0 10px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.icon-preview {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.icon-preview img {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.table-icon {
    --icon-hue: 220;
    display: inline-flex;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    overflow: hidden;
    vertical-align: middle;
}

.table-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.table-icon-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    background: hsl(var(--icon-hue) 55% 48%);
}

input[type="file"] {
    padding: 8px;
    background: #f8fafc;
}

/* —— Permissions panel —— */

.perm-active-summary {
    margin: 12px 0 16px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.92rem;
}

.perm-none {
    color: var(--text-muted);
}

.perm-tag {
    display: inline-block;
    margin: 2px 6px 2px 0;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.8rem;
    font-weight: 600;
}

.perm-role-fieldset {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px 8px;
    margin: 0 0 8px;
}

.perm-role-fieldset legend {
    padding: 0 6px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
}

.empty-state {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

/* —— Login —— */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #334155 100%);
    padding: 24px;
}

.auth-shell {
    width: 100%;
    max-width: 440px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 36px 32px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
    margin: 0 0 6px;
    font-size: 1.75rem;
}

.auth-card .auth-tagline {
    margin: 0 0 28px;
    color: var(--text-muted);
}

.auth-divider {
    margin: 28px 0 20px;
    border: 0;
    border-top: 1px solid var(--border);
}

.auth-card h2 {
    font-size: 1rem;
    margin: 0 0 12px;
}

.panel--wide {
    grid-column: 1 / -1;
}

.panel-subheading {
    margin: 24px 0 12px;
    font-size: 1rem;
}

.muted {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.assign-app-picker {
    margin-bottom: 20px;
}

.inline-form {
    display: inline;
    margin: 0;
}

.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent-strong);
    cursor: pointer;
    font: inherit;
    text-decoration: underline;
}

.assignment-table code {
    font-size: 0.9em;
}

.admin-subnav {
    display: flex;
    gap: 16px;
    margin: 0 0 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.admin-subnav a {
    text-decoration: none;
    color: var(--text-muted);
}

.admin-subnav a.is-active {
    color: var(--accent-strong);
    font-weight: 600;
}

.admin-apps-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin: -8px 0 20px;
    font-size: 0.9rem;
}

.admin-apps-subnav a {
    text-decoration: none;
    color: var(--text-muted);
}

.admin-apps-subnav a.is-active {
    color: var(--accent-strong);
    font-weight: 600;
}

.panel-footer-actions {
    margin-top: 20px;
}

.mail-queue-table {
    font-size: 0.9rem;
}

.mail-queue-table .mail-error-cell {
    max-width: 12rem;
    color: var(--text-muted);
}

.mail-queue-actions {
    white-space: nowrap;
}

.mail-queue-actions .inline-form + .inline-form {
    margin-left: 8px;
}

.mail-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}

.mail-status--pending {
    background: #fef3c7;
    color: #92400e;
}

.mail-status--sent {
    background: #d1fae5;
    color: #065f46;
}

.mail-status--failed {
    background: #fee2e2;
    color: #991b1b;
}

.btn-link--danger {
    color: #b91c1c;
}

/* —— Responsive —— */

@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        padding: 16px;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sidebar-footer {
        display: none;
    }

    .main {
        padding: 20px 16px 32px;
    }
}
