/* EZZiti — Dashboard styles */

/* ── 1. Custom properties & base reset ────────────────────────────── */

:root {
    --brand-primary: #0066FF;
    --brand-primary-hover: #0052cc;
    --brand-secondary: #00489f;
    --brand-secondary-hover: #003d82;

    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-success: #16a34a;

    --text-primary: #111827;
    --text-secondary: #374151;
    --text-tertiary: #6b7280;
    --text-muted: #9ca3af;

    --bg-page: #f9fafb;
    --bg-white: #ffffff;
    --bg-subtle: #f3f4f6;
    --bg-divider: #e5e7eb;

    --border-card: #d1d5db;
    --border-divider: #e5e7eb;
    --border-dark: #9ca3af;

    --radius: 5px;
    --radius-lg: 7px;
    --radius-pill: 9999px;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-nav: 0 1px 2px rgba(0,0,0,0.04);

    --height-field: 56px;
    --height-btn: 48px;
    --height-nav: 64px;
}

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

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-page);
}

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

h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 8px; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 0 0 12px; color: var(--text-primary); }
h3 { font-size: 1rem; font-weight: 600; margin: 0 0 8px; color: var(--text-secondary); }

p { margin: 0 0 12px; color: var(--text-secondary); }

pre, code {
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.875rem;
}

pre {
    background: var(--bg-subtle);
    border: 1px solid var(--border-divider);
    border-radius: var(--radius);
    padding: 12px 16px;
    overflow-x: auto;
    margin: 8px 0 16px;
}

code {
    background: var(--bg-subtle);
    padding: 2px 6px;
    border-radius: 3px;
}

pre code { background: none; padding: 0; }

/* ── 2. Navigation ────────────────────────────────────────────────── */

.main-nav {
    display: flex;
    align-items: center;
    height: var(--height-nav);
    padding: 0 24px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-divider);
    box-shadow: var(--shadow-nav);
}

.nav-brand {
    display: inline-flex;
    align-items: center;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
    text-decoration: none;
    margin-right: 32px;
}

.nav-brand img {
    height: 40px;
}

.nav-brand:hover { text-decoration: none; }

.nav-version {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-right: 16px;
    align-self: center;
}

.nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav-links a {
    padding: 8px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.nav-links a:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-links a.nav-active {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.nav-toggle:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.nav-logout {
    margin-left: auto;
    margin-top: 0;
}

.nav-logout button {
    background: none;
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.nav-logout button:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

/* Eznet switcher */
.eznet-switcher {
    position: relative;
    margin: 0 12px;
}
.eznet-switcher-label {
    display: inline-block;
    padding: 6px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}
.eznet-switcher-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
}
.eznet-switcher-btn:hover {
    background: var(--bg-white);
}
.eznet-switcher-name {
    font-weight: 600;
}
.eznet-switcher-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}
.eznet-switcher-arrow {
    font-size: 0.65rem;
    color: var(--text-secondary);
}
.eznet-switcher-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    margin-top: 4px;
    background: var(--bg-white);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
}
.eznet-switcher-open .eznet-switcher-menu {
    display: block;
}
.eznet-switcher-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
    text-align: left;
}
.eznet-switcher-item:hover {
    background: var(--bg-subtle);
}
.eznet-switcher-selected {
    font-weight: 600;
}
.eznet-item-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

/* ── 3. Layout ────────────────────────────────────────────────────── */

.main-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px;
}

/* ── 4. Cards ─────────────────────────────────────────────────────── */

.card {
    background: var(--bg-white);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
    overflow-x: auto;
}

.danger-zone {
    border-left: 4px solid var(--color-danger);
}

/* ── 5. Headers ───────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h1 { margin: 0; }

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

.section-header h2 { margin: 0; }

/* ── 6. Tables ────────────────────────────────────────────────────── */

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead th {
    text-align: left;
    background: var(--bg-subtle);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    padding: 10px 16px;
}

.data-table thead th:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.data-table thead th:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }

.data-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-divider);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody td a { font-weight: 500; }

/* ── 7. Buttons ───────────────────────────────────────────────────── */

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--height-btn);
    padding: 12px 24px;
    background: var(--brand-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: var(--brand-primary-hover);
    text-decoration: none;
    color: #fff;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--height-btn);
    padding: 12px 24px;
    background: var(--bg-white);
    color: var(--text-primary);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
    background: var(--bg-subtle);
    border-color: var(--border-divider);
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--height-btn);
    padding: 12px 24px;
    background: var(--color-danger);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

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

.btn-sm {
    min-height: auto;
    padding: 6px 14px;
    font-size: 0.8rem;
}

/* plain btn-sm (no color class) — ghost button */
button.btn-sm:not(.btn-primary):not(.btn-danger) {
    background: none;
    color: var(--brand-primary);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

button.btn-sm:not(.btn-primary):not(.btn-danger):hover {
    background: var(--bg-subtle);
}

/* ── 8. Forms ─────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
    height: var(--height-field);
    padding: 12px 14px;
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-white);
    transition: border-color 0.15s;
}

.form-group textarea {
    height: auto;
    min-height: 80px;
    resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.form-error {
    color: var(--color-danger);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 0.875rem;
}

.form-success {
    color: var(--color-success);
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 0.875rem;
}
.flash {
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-weight: 600;
}
.flash-success {
    color: var(--color-success);
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}
.flash-error {
    color: var(--color-danger);
    background: #fef2f2;
    border: 1px solid #fecaca;
}
.grant-everyone-warning {
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 8px 12px;
    margin: 8px 0;
    font-size: 0.85rem;
}

/* ── 8b. Grant search autocomplete ────────────────────────────────── */

.grant-search-wrap {
    position: relative;
}

.grant-search-wrap input[type="search"] {
    width: 100%;
    height: var(--height-field);
    padding: 12px 14px;
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-white);
    margin: 8px 0;
}

.grant-search-wrap input[type="search"]:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

.grant-search-results {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--bg-white);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    max-height: 240px;
    overflow-y: auto;
    z-index: 50;
}

.grant-search-results:empty {
    display: none;
}

.grant-search-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-divider);
    text-align: left;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
    cursor: pointer;
}

.grant-search-item:last-child {
    border-bottom: none;
}

.grant-search-item:hover {
    background: var(--bg-subtle);
}

/* ── 9. Device detail specifics ───────────────────────────────────── */

.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    vertical-align: middle;
}

.status-online  { background: #dcfce7; color: #166534; }
.status-offline { background: #fee2e2; color: #991b1b; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-unknown { background: var(--bg-subtle); color: var(--text-tertiary); }

.device-dns {
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.875rem;
    color: var(--text-tertiary);
    margin-top: -4px;
    margin-bottom: 20px;
}

.grant-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-divider);
    font-size: 0.9rem;
}

.grant-item:last-child { border-bottom: none; }

.jwt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.jwt-header p {
    margin: 0;
}

.jwt-token {
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
    background: var(--bg-subtle);
    border: 1px solid var(--border-divider);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 0.8rem;
    word-break: break-all;
    white-space: pre-wrap;
    overflow-x: auto;
}

.copy-btn {
    background: var(--bg-white);
    border: 1px solid var(--border-divider);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    color: var(--text-secondary);
    line-height: 1;
}

.copy-btn:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

/* ── 10. Downloads ────────────────────────────────────────────────── */

.download-links {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.version-label {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
}

/* ── 11. Login & welcome ──────────────────────────────────────────── */

.login-page,
.welcome-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-page);
}

.login-card,
.welcome-card {
    max-width: 400px;
    width: 100%;
    text-align: center;
    background: var(--bg-white);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: var(--shadow-card);
}

.login-card h1,
.welcome-card h1 {
    font-size: 1.35rem;
    margin-bottom: 8px;
}

.login-card p,
.welcome-card p {
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

.login-error {
    color: var(--color-danger);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 0.875rem;
    text-align: left;
}

.login-providers {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.login-provider-btn {
    display: block;
    padding: 14px;
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: background 0.15s, border-color 0.15s;
}

.login-provider-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--border-dark);
    text-decoration: none;
}

.welcome-skip {
    display: block;
    margin-top: 12px;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    text-decoration: none;
}

.welcome-skip:hover {
    text-decoration: underline;
}

/* ── 12. Stat cards ──────────────────────────────────────────────── */

.stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    text-align: center;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s;
}

.stat-card:hover {
    border-color: var(--brand-primary);
    text-decoration: none;
    color: inherit;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

/* ── 13. Page-specific spacing ────────────────────────────────────── */

.overview-page,
.devices-page {
    min-width: fit-content;
}

.device-detail-page,
.members-page,
.settings-page,
.downloads-page,
.activity-page,
.profile-page {
    /* pages inherit layout from .main-content */
}

.device-name-link {
    font-weight: 600;
}

.profile-info {
    margin: 0;
}

.profile-info dt {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 12px;
}

.profile-info dt:first-child {
    margin-top: 0;
}

.profile-info dd {
    margin: 4px 0 0;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.activity-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.activity-search input[type="text"] {
    height: var(--height-field);
    padding: 8px 14px;
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-white);
    min-width: 280px;
}

.activity-search input[type="text"]:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

.activity-search a {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ── 14. My Eznets page ──────────────────────────────────────────── */

.status-active    { background: #dcfce7; color: #166534; }
.status-suspended { background: #fef3c7; color: #92400e; }

.link-button {
    background: none;
    border: none;
    color: var(--brand-primary);
    cursor: pointer;
    font: inherit;
    padding: 0;
    text-decoration: none;
}

.link-button:hover {
    text-decoration: underline;
}

.inline-form {
    display: inline;
}

.create-eznet-section {
    margin-bottom: 20px;
}

.create-eznet-section > summary {
    cursor: pointer;
    list-style: none;
    display: inline-block;
}

.create-eznet-section > summary::-webkit-details-marker { display: none; }

.create-eznet-form {
    margin-top: 12px;
    padding: 20px;
    max-width: 480px;
}

/* ── 15. Responsive ──────────────────────────────────────────────── */

@media (max-width: 768px) {
    .main-nav {
        flex-wrap: wrap;
        height: auto;
        min-height: var(--height-nav);
        padding: 0 16px;
    }

    .nav-toggle {
        display: block;
        margin-left: auto;
    }

    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 2px;
        padding: 8px 0;
        order: 3;
    }

    .nav-links.nav-open {
        display: flex;
    }

    .nav-links a {
        padding: 10px 14px;
    }

    .eznet-switcher {
        margin: 4px 14px;
        order: 2;
    }
    .eznet-switcher-btn {
        width: 100%;
    }
    .eznet-switcher-menu {
        position: relative;
        width: 100%;
        box-shadow: none;
        border: none;
        border-top: 1px solid var(--border-divider);
        margin-top: 2px;
    }

    .nav-logout {
        margin-left: 0;
        margin-top: 4px;
        padding-top: 8px;
        border-top: 1px solid var(--border-divider);
    }

    .nav-logout button {
        width: 100%;
    }

    .main-content {
        padding: 16px;
    }

    .stat-cards {
        grid-template-columns: 1fr;
    }
}
