/* ================================================================
   Account Manager Pro – Frontend Styles
   Design: Minimal corporate-dark, clean spacing, sharp accents
   ================================================================ */

:root {
    --am-bg:          #0f1117;
    --am-surface:     #181c25;
    --am-surface-2:   #1f2434;
    --am-border:      #2a2f42;
    --am-border-2:    #353b52;
    --am-text:        #e8eaf0;
    --am-text-muted:  #8892a4;
    --am-text-faint:  #555e72;
    --am-primary:     #4f6ef7;
    --am-primary-h:   #3a58e4;
    --am-primary-l:   rgba(79,110,247,.12);
    --am-success:     #22c55e;
    --am-success-l:   rgba(34,197,94,.12);
    --am-warning:     #f59e0b;
    --am-warning-l:   rgba(245,158,11,.12);
    --am-danger:      #ef4444;
    --am-danger-l:    rgba(239,68,68,.12);
    --am-secondary:   #8892a4;
    --am-radius-sm:   6px;
    --am-radius:      10px;
    --am-radius-lg:   16px;
    --am-shadow:      0 4px 24px rgba(0,0,0,.4);
    --am-shadow-sm:   0 2px 8px rgba(0,0,0,.3);
    --am-font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --am-font-mono:   'JetBrains Mono', 'Fira Code', monospace;
    --am-transition:  0.18s ease;
}

/* ── Reset ───────────────────────────────────────────────── */
.am-wrap *, .am-wrap *::before, .am-wrap *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Wrap ────────────────────────────────────────────────── */
.am-wrap {
    font-family: var(--am-font);
    color: var(--am-text);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Login / Register Card ───────────────────────────────── */
.am-login-wrap,
.am-register-wrap {
    display: flex;
    justify-content: center;
    padding: 48px 16px;
}

.am-card {
    background: var(--am-surface);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-lg);
    padding: 36px;
    box-shadow: var(--am-shadow);
}

.am-login-wrap .am-card,
.am-register-wrap .am-card {
    width: 100%;
    max-width: 440px;
}

/* ── Card Header ─────────────────────────────────────────── */
.am-card-header {
    text-align: center;
    margin-bottom: 28px;
}

.am-logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: var(--am-primary-l);
    border-radius: 50%;
    color: var(--am-primary);
    margin-bottom: 16px;
}
.am-logo-icon svg { width: 28px; height: 28px; }

.am-card-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--am-text);
    margin-bottom: 6px;
}

.am-card-subtitle {
    color: var(--am-text-muted);
    font-size: 13px;
}

.am-card-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 13px;
    color: var(--am-text-muted);
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: center;
}

/* ── Alerts ──────────────────────────────────────────────── */
.am-alert {
    padding: 10px 14px;
    border-radius: var(--am-radius-sm);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
    animation: am-fade-in 0.2s ease;
}
.am-alert-error   { background: var(--am-danger-l);  color: var(--am-danger);  border: 1px solid rgba(239,68,68,.25); }
.am-alert-success { background: var(--am-success-l); color: var(--am-success); border: 1px solid rgba(34,197,94,.25); }

/* ── Form ────────────────────────────────────────────────── */
.am-form { display: flex; flex-direction: column; gap: 16px; }
.am-form-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.am-form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 640px) {
    .am-form-inline,
    .am-form-grid { grid-template-columns: 1fr; }
}

.am-field { display: flex; flex-direction: column; gap: 6px; }

.am-field-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.am-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--am-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.am-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
.am-required { color: var(--am-danger); }

.am-input {
    background: var(--am-surface-2);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-sm);
    color: var(--am-text);
    font-family: var(--am-font);
    font-size: 14px;
    padding: 10px 14px;
    transition: border-color var(--am-transition), box-shadow var(--am-transition);
    width: 100%;
    outline: none;
}
.am-input::placeholder { color: var(--am-text-faint); }
.am-input:focus {
    border-color: var(--am-primary);
    box-shadow: 0 0 0 3px var(--am-primary-l);
}
.am-input:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.am-input-group {
    position: relative;
    display: flex;
    align-items: center;
}
.am-input-group .am-input { padding-right: 42px; }

.am-input-toggle {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--am-text-faint);
    padding: 4px;
    line-height: 0;
    transition: color var(--am-transition);
}
.am-input-toggle:hover { color: var(--am-text-muted); }
.am-input-toggle svg { width: 16px; height: 16px; }

.am-select {
    background: var(--am-surface-2);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-sm);
    color: var(--am-text);
    font-family: var(--am-font);
    font-size: 14px;
    padding: 10px 14px;
    width: 100%;
    outline: none;
    cursor: pointer;
    transition: border-color var(--am-transition);
}
.am-select:focus { border-color: var(--am-primary); }

.am-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--am-text-muted);
}
.am-checkbox-label input { accent-color: var(--am-primary); }

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

/* ── Buttons ─────────────────────────────────────────────── */
.am-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: none;
    border-radius: var(--am-radius-sm);
    cursor: pointer;
    font-family: var(--am-font);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 20px;
    transition: all var(--am-transition);
    text-decoration: none;
    line-height: 1;
    white-space: nowrap;
}
.am-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.am-btn-primary  { background: var(--am-primary); color: #fff; }
.am-btn-primary:hover { background: var(--am-primary-h); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,110,247,.4); }

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

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

.am-btn-success { background: var(--am-success-l); color: var(--am-success); border: 1px solid rgba(34,197,94,.3); }
.am-btn-success:hover { background: var(--am-success); color: #fff; }

.am-btn-warning { background: var(--am-warning-l); color: var(--am-warning); border: 1px solid rgba(245,158,11,.3); }
.am-btn-warning:hover { background: var(--am-warning); color: #fff; }

.am-btn-danger { background: var(--am-danger-l); color: var(--am-danger); border: 1px solid rgba(239,68,68,.3); }
.am-btn-danger:hover { background: var(--am-danger); color: #fff; }

.am-btn-sm { font-size: 12px; padding: 7px 12px; }
.am-btn-sm svg { width: 13px; height: 13px; }

.am-btn:disabled, .am-btn[disabled] { opacity: .5; cursor: not-allowed; transform: none !important; }

.am-btn-loader {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: am-spin 0.7s linear infinite;
    display: inline-block;
}

/* ── Links ───────────────────────────────────────────────── */
.am-link { color: var(--am-primary); text-decoration: none; font-weight: 600; font-size: 13px; }
.am-link:hover { text-decoration: underline; }
.am-already-logged { color: var(--am-text-muted); font-size: 14px; }
.am-notice { color: var(--am-text-muted); font-size: 14px; }

/* ── Dashboard Layout ────────────────────────────────────── */
.am-dashboard-wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 0 60px;
}

.am-dashboard-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px 0 20px;
    border-bottom: 1px solid var(--am-border);
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.am-avatar {
    width: 52px; height: 52px;
    background: var(--am-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -0.5px;
}

.am-dashboard-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.am-dashboard-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--am-text);
}

.am-sub-parent-label {
    font-size: 12px;
    color: var(--am-text-muted);
    width: 100%;
}

.am-logout-btn { margin-left: auto; }

/* ── Badges ──────────────────────────────────────────────── */
.am-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.am-badge-primary   { background: var(--am-primary-l); color: var(--am-primary); }
.am-badge-secondary { background: var(--am-surface-2); color: var(--am-text-muted); border: 1px solid var(--am-border); }
.am-badge-success   { background: var(--am-success-l); color: var(--am-success); }
.am-badge-danger    { background: var(--am-danger-l);  color: var(--am-danger); }
.am-badge-warning   { background: var(--am-warning-l); color: var(--am-warning); }

/* ── Tabs ────────────────────────────────────────────────── */
.am-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--am-border);
    margin-bottom: 24px;
    overflow-x: auto;
}

.am-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--am-text-muted);
    cursor: pointer;
    font-family: var(--am-font);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 16px;
    margin-bottom: -1px;
    transition: all var(--am-transition);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}
.am-tab:hover { color: var(--am-text); }
.am-tab-active { color: var(--am-primary); border-bottom-color: var(--am-primary); }

.am-tab-badge {
    background: var(--am-border);
    color: var(--am-text-muted);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    min-width: 20px;
    text-align: center;
}
.am-tab-active .am-tab-badge {
    background: var(--am-primary-l);
    color: var(--am-primary);
}

.am-tab-panel { display: none; animation: am-fade-in 0.2s ease; }
.am-tab-panel-active { display: block; }

/* ── Dashboard Cards ─────────────────────────────────────── */
.am-dashboard-wrap .am-card {
    margin-bottom: 16px;
    padding: 28px;
}

.am-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--am-text);
    margin-bottom: 6px;
}
.am-section-desc {
    font-size: 13px;
    color: var(--am-text-muted);
    margin-bottom: 20px;
}

/* ── Collapsible ─────────────────────────────────────────── */
.am-card-collapsible { padding: 0; overflow: hidden; }

.am-collapsible-trigger {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--am-font);
    font-size: 14px;
    font-weight: 700;
    color: var(--am-primary);
    padding: 20px 28px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: color var(--am-transition);
}
.am-collapsible-trigger svg { width: 16px; height: 16px; transition: transform var(--am-transition); }
.am-collapsible-trigger[aria-expanded="true"] { color: var(--am-text); border-bottom: 1px solid var(--am-border); }
.am-collapsible-trigger[aria-expanded="true"] svg { transform: rotate(45deg); }

.am-collapsible-body { padding: 24px 28px 28px; }

/* ── Subaccounts List ────────────────────────────────────── */
.am-subaccounts-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.am-subaccount-item {
    background: var(--am-surface);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color var(--am-transition);
}
.am-subaccount-item:hover { border-color: var(--am-border-2); }
.am-subaccount-item.am-suspended { opacity: .6; }

.am-sub-avatar {
    width: 38px; height: 38px;
    background: var(--am-surface-2);
    border: 1px solid var(--am-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: var(--am-text-muted);
    flex-shrink: 0;
}

.am-sub-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.am-sub-info strong {
    font-size: 14px;
    color: var(--am-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.am-sub-info span {
    font-size: 12px;
    color: var(--am-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.am-sub-status { flex-shrink: 0; }

.am-sub-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* ── Invite Links ─────────────────────────────────────────── */
.am-invite-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

.am-invite-item {
    background: var(--am-surface);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.am-invite-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.am-invite-link {
    font-family: var(--am-font-mono);
    font-size: 12px;
    color: var(--am-primary);
    background: var(--am-surface-2);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-sm);
    padding: 4px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.am-invite-meta { font-size: 12px; color: var(--am-text-muted); }

.am-invite-item-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.am-copy-invite-btn { position: relative; }
.am-copied-label {
    font-size: 12px;
    color: var(--am-success);
    font-weight: 600;
    padding: 0 4px;
}

.am-empty-state-sm { padding: 18px 0 4px; text-align: center; }
.am-empty-state-sm p { color: var(--am-text-muted); font-size: 13px; margin: 0; }

/* ── Access Control ──────────────────────────────────────── */
.am-access-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.am-access-selector .am-label { white-space: nowrap; flex-shrink: 0; }
.am-access-selector .am-select { max-width: 360px; }

.am-access-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.am-search-field { flex: 1; max-width: 280px; }
.am-search-field .am-input { padding: 8px 12px; font-size: 13px; }

.am-access-list {
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius);
    overflow: hidden;
    margin-bottom: 20px;
    max-height: 420px;
    overflow-y: auto;
}

.am-access-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--am-border);
    transition: background var(--am-transition);
}
.am-access-item:last-child { border-bottom: none; }
.am-access-item:hover { background: var(--am-surface-2); }

.am-access-item-info {
    flex: 1;
    min-width: 0;
}
.am-access-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--am-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.am-access-item-url {
    font-size: 11px;
    color: var(--am-text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--am-font-mono);
}

.am-access-type {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 7px;
    border-radius: 4px;
    background: var(--am-border);
    color: var(--am-text-faint);
    flex-shrink: 0;
}

/* Toggle switch */
.am-toggle-wrap { flex-shrink: 0; }
.am-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
}
.am-toggle input { opacity: 0; width: 0; height: 0; }
.am-toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--am-border);
    border-radius: 22px;
    transition: background var(--am-transition);
}
.am-toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px; height: 16px;
    left: 3px; bottom: 3px;
    background: var(--am-text-faint);
    border-radius: 50%;
    transition: transform var(--am-transition), background var(--am-transition);
}
.am-toggle input:checked + .am-toggle-slider { background: var(--am-primary-l); }
.am-toggle input:checked + .am-toggle-slider::before {
    transform: translateX(18px);
    background: var(--am-primary);
}

/* ── Loading ─────────────────────────────────────────────── */
.am-loading {
    text-align: center;
    padding: 40px;
    color: var(--am-text-faint);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.am-loading::before {
    content: '';
    display: block;
    width: 24px; height: 24px;
    border: 2px solid var(--am-border);
    border-top-color: var(--am-primary);
    border-radius: 50%;
    animation: am-spin 0.7s linear infinite;
}

/* ── Empty state ─────────────────────────────────────────── */
.am-empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--am-text-muted);
    font-size: 14px;
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.am-empty-state svg {
    width: 64px; height: 64px;
    color: var(--am-border-2);
}

/* ── Modal ───────────────────────────────────────────────── */
.am-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: am-fade-in 0.15s ease;
}
.am-modal {
    background: var(--am-surface);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-lg);
    padding: 32px;
    max-width: 440px;
    width: 100%;
    box-shadow: var(--am-shadow);
}
.am-modal-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--am-text);
    margin-bottom: 10px;
}
.am-modal-body {
    font-size: 14px;
    color: var(--am-text-muted);
    margin-bottom: 24px;
    line-height: 1.6;
}
.am-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
    .am-dashboard-wrap { padding: 0 4px 40px; }
    .am-card { padding: 20px; }
    .am-subaccount-item { flex-wrap: wrap; }
    .am-sub-actions { width: 100%; justify-content: flex-end; }
    .am-dashboard-header { gap: 12px; }
    .am-logout-btn { order: -1; margin-left: auto; }
}

/* ── Keyframes ───────────────────────────────────────────── */
@keyframes am-fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes am-spin    { to { transform: rotate(360deg); } }

/* ── Edit Subaccount Modal ───────────────────────────────── */
.am-modal-wide {
    max-width: 520px;
    width: 95%;
    position: relative;
}
.am-modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--am-text-muted);
    padding: 0 4px;
    transition: color .15s;
}
.am-modal-close:hover { color: var(--am-text); }
.am-modal-sub-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 4px;
    font-size: 13px;
    color: var(--am-text-muted);
    background: var(--am-surface);
    border-radius: 8px;
    padding: 8px 12px;
}
.am-modal-sub-info strong {
    color: var(--am-text);
    font-family: monospace;
    font-size: 13px;
}
.am-edit-sub-btn {
    color: var(--am-primary);
    border-color: var(--am-primary);
}
.am-edit-sub-btn:hover {
    background: var(--am-primary);
    color: #fff;
}
