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

:root {
    --bg:        #f0f2f5;
    --sidebar:   #1e2a38;
    --sidebar-t: #a8b8cc;
    --sidebar-a: #ffffff;
    --sidebar-h: #2d3e52;
    --header:    #243447;
    --primary:   #3b82f6;
    --danger:    #ef4444;
    --border:    #d1d5db;
    --text:      #1f2937;
    --muted:     #6b7280;
    --white:     #ffffff;
    --radius:    6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    height: 100vh;
    overflow: hidden;
}

/* ── Helpers ── */
.hidden { display: none !important; }
.error  { color: var(--danger); font-size: 13px; margin-top: 6px; }

/* ── Login / Setup / Pending ── */
#view-login,
#view-setup,
#view-pending {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg);
}

.login-box {
    background: var(--white);
    border-radius: var(--radius);
    padding: 40px 36px;
    width: 340px;
    box-shadow: 0 4px 24px rgba(0,0,0,.1);
}

.login-box h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--header);
    margin-bottom: 28px;
    text-align: center;
    letter-spacing: .5px;
}

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

input[type=text],
input[type=password],
input[type=number],
textarea,
select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: var(--white);
    outline: none;
    transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--primary); }

button {
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    padding: 8px 16px;
    transition: background .15s, opacity .15s;
}

.login-box button[type=submit],
.login-box button[type=button] {
    width: 100%;
    font-weight: 600;
    padding: 10px;
    margin-top: 6px;
}

.login-box button[type=submit] {
    background: var(--primary);
    color: var(--white);
}
.login-box button[type=submit]:hover:not(:disabled) { background: #2563eb; }

button:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-outline {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--text); color: var(--text); }

.setup-note {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 24px;
    text-align: center;
    line-height: 1.5;
}

.pending-notice {
    background: #fef9c3;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 16px;
    font-size: 13px;
    line-height: 1.6;
    color: #92400e;
}
.pending-notice p + p { margin-top: 6px; }

/* ── App layout ── */
#view-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
#topbar {
    display: flex;
    align-items: center;
    background: var(--header);
    color: var(--white);
    padding: 0 20px;
    height: 48px;
    flex-shrink: 0;
    gap: 24px;
}

.logo {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .5px;
}

#topnav { display: flex; align-items: center; gap: 4px; flex: 1; }
#nav-admin-wrap { display: flex; align-items: center; }
#topnav a {
    color: #94a3b8;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    transition: color .15s, background .15s;
}
#topnav a:hover, #topnav a.active {
    color: var(--white);
    background: rgba(255,255,255,.1);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #94a3b8;
}

#btn-logout {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #475569;
    font-size: 12px;
    padding: 4px 10px;
}
#btn-logout:hover { border-color: #94a3b8; color: var(--white); }

/* Body */
#app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
#sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 8px;
    color: var(--sidebar-a);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .6;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
#sidebar-header button {
    opacity: 0;
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    border-radius: 3px;
    transition: opacity .1s, background .1s;
}
#sidebar:hover #sidebar-header button { opacity: .7; }
#sidebar-header button:hover { opacity: 1 !important; background: rgba(255,255,255,.15); }

#sidebar-add-form {
    padding: 8px 12px;
    background: var(--sidebar-h);
    border-bottom: 1px solid rgba(255,255,255,.07);
}
#sidebar-add-form select,
#sidebar-add-form input { margin-bottom: 4px; }

#sidebar {
    width: 420px;
    flex-shrink: 0;
    background: var(--sidebar);
    overflow-y: auto;
    padding: 12px 0;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    color: var(--sidebar-t);
    cursor: pointer;
    user-select: none;
    font-size: 13px;
    border-left: 3px solid transparent;
    transition: background .1s, color .1s;
}
.tree-item:hover { background: var(--sidebar-h); color: var(--sidebar-a); }
.tree-item.active {
    background: var(--sidebar-h);
    color: var(--sidebar-a);
    border-left-color: var(--primary);
}
.tree-item .toggle { width: 12px; font-size: 10px; }
.tree-item.child { padding-left: 36px; }
.tree-item .tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .tree-add-btn {
    opacity: 0;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 3px;
    transition: opacity .1s, background .1s;
    flex-shrink: 0;
}
.tree-item:hover .tree-add-btn { opacity: .7; }
.tree-item .tree-add-btn:hover { opacity: 1 !important; background: rgba(255,255,255,.15); }

/* Inline form in tree */
.tree-inline-form {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 16px 4px 36px;
    background: var(--sidebar-h);
}
.tree-inline-form.deep { padding-left: 56px; }
.tree-inline-input {
    flex: 1;
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid var(--primary);
    border-radius: 3px;
    background: var(--white);
    color: var(--text);
    outline: none;
    min-width: 0;
}
.tree-inline-form .btn-sm { padding: 2px 6px; font-size: 11px; }

/* Context menu */
.ctx-menu {
    position: fixed;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    z-index: 2000;
    min-width: 180px;
    padding: 4px 0;
}
.ctx-item {
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    user-select: none;
}
.ctx-item:hover { background: var(--bg); }
.ctx-danger { color: var(--danger); }

/* Reset page */
.admin-tab-danger { color: var(--danger) !important; }
.admin-tab-danger.active { border-bottom-color: var(--danger) !important; }

.reset-danger-box {
    max-width: 520px;
    border: 2px solid var(--danger);
    border-radius: 8px;
    padding: 28px 32px;
    background: #fff5f5;
}
.reset-title { margin: 0 0 12px; font-size: 16px; color: var(--danger); }
.reset-desc  { margin: 0 0 20px; color: var(--text); line-height: 1.6; font-size: 14px; }
.reset-confirm-row { margin-bottom: 20px; }
.reset-confirm-row label { display: block; font-size: 13px; margin-bottom: 6px; }
.reset-confirm-row input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}
.btn-danger-lg {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
.btn-danger-lg:disabled { opacity: .4; cursor: not-allowed; }
.btn-danger-lg:not(:disabled):hover { opacity: .85; }
.ctx-divider { border-top: 1px solid var(--border); margin: 4px 0; }

/* Toast */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: #1e293b;
    color: #f1f5f9;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 3000;
    pointer-events: none;
    opacity: 1;
    transition: opacity .3s;
}
.toast.hidden { display: none; }
.toast.fade-out { opacity: 0; }

/* Content */
#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--white);
}

#entries-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#search { max-width: 280px; }

#btn-add-entry {
    background: var(--primary);
    color: var(--white);
    font-size: 13px;
    padding: 6px 14px;
    margin-left: auto;
}
#btn-add-entry:hover { background: #2563eb; }

/* Entries table */
#entries-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#entries-table thead th {
    text-align: left;
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
    position: sticky;
    top: 0;
}

#entries-table tbody tr {
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background .1s;
}
#entries-table tbody tr:hover { background: #f8fafc; }

#entries-table td {
    padding: 9px 14px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-password { font-family: monospace; letter-spacing: 2px; color: var(--muted); }
.td-copyable { white-space: nowrap; }
.td-copyable .btn-copy-icon {
    opacity: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    margin-left: 4px;
    vertical-align: middle;
    transition: opacity .15s;
}
tr:hover .td-copyable .btn-copy-icon { opacity: .5; }
tr:hover .td-copyable .btn-copy-icon:hover { opacity: 1; }
.td-rdp { color: var(--primary); font-size: 12px; }
.td-rdp-active { cursor: pointer; }
.td-url-active { cursor: pointer; color: var(--primary); }
.td-url-active:hover span { text-decoration: underline; }
.td-rdp-active:hover .rdp-link { text-decoration: underline; }
.td-rdp-active:hover { background: rgba(59,130,246,.06); }

.btn-copy {
    background: none;
    border: 1px solid var(--border);
    padding: 2px 6px;
    font-size: 11px;
    color: var(--muted);
    border-radius: 4px;
    margin-left: 6px;
}
.btn-copy:hover { border-color: var(--primary); color: var(--primary); }

/* ── Modal ── */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#modal {
    background: var(--white);
    border-radius: var(--radius);
    width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
}

#modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
}

.tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    border-radius: 0;
    margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover  { color: var(--text); }

.tab-content { padding: 20px; }

.input-row {
    display: flex;
    gap: 6px;
    align-items: center;
}
.input-row input { flex: 1; }
.input-row button {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 8px 10px;
    font-size: 13px;
}
.input-row button:hover { border-color: var(--primary); color: var(--primary); }

#rdp-details {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 8px;
}
#rdp-details .field { margin-bottom: 10px; }
#rdp-details input[type=number] { width: 80px; }

.radio-group { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.radio-group label { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: normal; text-transform: none; }

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

#btn-save-entry  { background: var(--primary); color: var(--white); }
#btn-save-entry:hover { background: #2563eb; }
#btn-delete-entry { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
#btn-delete-entry:hover { background: #fee2e2; }
#btn-close-modal { background: var(--bg); color: var(--muted); margin-left: auto; }
#btn-close-modal:hover { background: var(--border); }

/* History table */
#history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#history-table th {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}
#history-table td { padding: 8px 12px; border-bottom: 1px solid #f3f4f6; }

/* Admin sections */
.admin-section { padding: 20px; }
.admin-section h2 { font-size: 16px; margin-bottom: 16px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left;
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}
.data-table td { padding: 9px 14px; border-bottom: 1px solid #f3f4f6; }
.data-table tr:hover td { background: #f8fafc; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-admin   { background: #ede9fe; color: #7c3aed; }
.badge-editor  { background: #dbeafe; color: #1d4ed8; }
.badge-reader  { background: #f0fdf4; color: #166534; }
.badge-active  { background: #f0fdf4; color: #166534; }
.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-blocked { background: #fef2f2; color: #991b1b; }

.btn-sm {
    font-size: 12px;
    padding: 4px 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm.danger:hover { border-color: var(--danger); color: var(--danger); }

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: #2563eb; }

/* ── Admin panel ── */
#admin-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.admin-nav {
    display: flex;
    gap: 2px;
    padding: 12px 20px 0;
    border-bottom: 1px solid var(--border);
    background: var(--white);
    flex-shrink: 0;
}

.admin-tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    border-radius: 0;
    margin-bottom: -1px;
}
.admin-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.admin-tab-btn:hover  { color: var(--text); }

.sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.sub-tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    margin-bottom: -1px;
}
.sub-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.sub-tab-btn:hover  { color: var(--text); }

.admin-pane {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.admin-toolbar {
    display: flex;
    align-items: center;
    margin-bottom: 14px;
    gap: 10px;
}

.admin-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.admin-inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.admin-inline-form input,
.admin-inline-form select {
    width: auto;
    flex: 1;
    min-width: 140px;
}

/* Profile card */
.profile-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
}

.profile-card-header {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}
.profile-card-header:hover { background: #f8fafc; }

.profile-card-title {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
}

.profile-card-meta {
    font-size: 12px;
    color: var(--muted);
}

.profile-card-body {
    border-top: 1px solid var(--border);
    padding: 12px 14px;
}

.members-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 10px;
}
.members-table th {
    text-align: left;
    padding: 6px 10px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.members-table td {
    padding: 7px 10px;
    border-bottom: 1px solid #f3f4f6;
}

.add-member-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.add-member-form select { width: auto; flex: 1; min-width: 140px; }

/* Group admin list */
.group-admin-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #f3f4f6;
    background: var(--white);
    gap: 10px;
    font-size: 13px;
}
.group-admin-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.group-admin-item:last-child  { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }
.group-admin-name { flex: 1; }
.group-admin-meta { font-size: 12px; color: var(--muted); }

/* ── Notices ── */
.notice-warning,
.notice-success {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.notice-warning {
    background: #fef9c3;
    border: 1px solid #fde68a;
    color: #92400e;
}
.notice-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}
.notice-success code {
    font-size: 14px;
    letter-spacing: 1px;
    padding: 3px 8px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: monospace;
}

/* ── Nav badge ── */
.nav-badge {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ── Confirm dialog ── */
#confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}
#confirm-box {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px 28px;
    width: 360px;
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
}
#confirm-text {
    margin: 0 0 20px;
    line-height: 1.6;
    font-size: 14px;
    color: var(--text);
    white-space: pre-wrap;
}
.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
#confirm-ok {
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
#confirm-ok.c-danger  { background: var(--danger); color: #fff; }
#confirm-ok.c-danger:hover { opacity: .85; }
#confirm-ok.c-primary { background: var(--primary); color: #fff; }
#confirm-ok.c-primary:hover { background: #2563eb; }

/* ── Idle timeout banner ── */
#idle-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #fef3c7;
    border-bottom: 1px solid #f59e0b;
    color: #78350f;
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
}
#idle-banner a {
    color: var(--primary);
    font-weight: 700;
    margin-left: 8px;
    text-decoration: none;
}
#idle-banner a:hover { text-decoration: underline; }
