/* ============================================================
   个人网址管理 - 样式
   桌面：侧边栏 + 多列卡片网格
   手机：单列 + 底部标签
   ============================================================ */

:root {
    --primary: #2f6fed;
    --primary-weak: #eaf1ff;
    --danger: #e5484d;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --border: #e6e8eb;
    --text: #1f2329;
    --text-2: #646a73;
    --text-3: #9aa1ab;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 232px;
    --topbar-h: 60px;
    --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #4b86f0;
        --primary-weak: #1e2a44;
        --bg: #14161a;
        --surface: #1c1f24;
        --surface-2: #22262c;
        --border: #2c3138;
        --text: #e8eaed;
        --text-2: #a2a9b3;
        --text-3: #767d87;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .35);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    }
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

a {
    color: inherit;
    text-decoration: none;
}

input, select, button, textarea {
    font: inherit;
    color: inherit;
}

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

/* -------------------- 通用控件 -------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, opacity .15s;
}

.btn:hover {
    background: var(--surface-2);
}

.btn:active {
    opacity: .8;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary);
    filter: brightness(1.06);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    filter: brightness(1.06);
}

.btn-block {
    width: 100%;
}

.btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-2);
}

.field label em {
    color: var(--danger);
    font-style: normal;
}

.field input[type=text],
.field input[type=password],
.field input[type=search],
.field select,
.inline-form input {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa1ab' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 32px;
}

.field input:focus,
.field select:focus,
.inline-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-weak);
}

.form-error {
    margin: 0 0 12px;
    color: var(--danger);
    font-size: 13px;
}

.hint {
    margin: 10px 0 0;
    color: var(--text-3);
    font-size: 12px;
}

.only-mobile {
    display: none !important;
}

/* -------------------- 密码门 -------------------- */

.gate {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.gate-card {
    width: 100%;
    max-width: 360px;
    padding: 30px 26px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.gate-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 14px;
}

.gate-card h1 {
    margin: 0 0 6px;
    font-size: 20px;
    text-align: center;
}

.gate-tip {
    margin: 0 0 22px;
    color: var(--text-2);
    font-size: 13px;
    text-align: center;
}

.gate-error {
    margin: 0 0 12px;
    color: var(--danger);
    font-size: 13px;
}

.gate-foot {
    margin: 16px 0 0;
    color: var(--text-3);
    font-size: 12px;
    text-align: center;
}

/* -------------------- 布局 -------------------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100%;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.sidebar-head {
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 15px;
    font-weight: 600;
}

.group-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 12px 10px;
}

.group-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 38px;
    padding: 0 10px;
    margin-bottom: 2px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    text-align: left;
    cursor: pointer;
}

.group-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.group-item.active {
    background: var(--primary-weak);
    color: var(--primary);
    font-weight: 600;
}

.group-item .g-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-item .g-count {
    font-size: 12px;
    color: var(--text-3);
}

.group-item.active .g-count {
    color: var(--primary);
}

.sidebar-foot {
    padding: 10px;
    border-top: 1px solid var(--border);
}

.sidebar-btn {
    display: block;
    width: 100%;
    height: 36px;
    margin-bottom: 4px;
    padding: 0 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    text-align: left;
    cursor: pointer;
}

.sidebar-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    max-width: 460px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-3);
}

.search:focus-within {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-weak);
}

.search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 8px;
    border: none;
    background: transparent;
    outline: none;
}

.search input::-webkit-search-cancel-button {
    display: none;
}

.search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
}

.search-clear:hover {
    background: var(--border);
}

.content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 18px;
    -webkit-overflow-scrolling: touch;
}

.content-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 14px;
}

.content-head h2 {
    margin: 0;
    font-size: 16px;
}

.content-head .muted {
    font-size: 12px;
}

/* -------------------- 卡片网格 -------------------- */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
    gap: 12px;
    align-content: start;
}

.card {
    position: relative;
    display: block;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 6px 20px rgba(47, 111, 237, .14);
}

.card.is-top {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

.card-top {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.favicon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.favicon img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    display: none;
}

.favicon img.loaded {
    display: block;
}

.favicon .letter {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.card-text {
    min-width: 0;
    flex: 1;
}

.card-name {
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-note {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-host {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    opacity: 0;
    transition: opacity .12s ease;
}

.card:hover .card-actions,
.card:focus-within .card-actions {
    opacity: 1;
}

.card-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.card-actions button:hover {
    background: var(--surface-2);
    color: var(--text);
}

.card-actions button.pinned {
    color: var(--primary);
}

.card-actions button.danger:hover {
    color: var(--danger);
}

.badge-top {
    position: absolute;
    right: 10px;
    bottom: 9px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 7px;
    border-radius: 20px;
    background: var(--primary-weak);
    color: var(--primary);
    font-size: 11px;
}

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 70px 20px;
    color: var(--text-3);
    text-align: center;
}

.empty-icon {
    margin-bottom: 10px;
    color: var(--text-3);
}

.empty p {
    margin: 0;
    font-size: 13px;
}

/* -------------------- 底部标签 / 悬浮按钮 -------------------- */

.tabbar {
    display: none;
}

.fab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
    display: none;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 6px 18px rgba(47, 111, 237, .4);
    cursor: pointer;
    z-index: 30;
}

.fab:active {
    transform: scale(.95);
}

/* -------------------- 弹窗 / 抽屉 -------------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 28, .45);
}

.modal-box {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
}

.modal-small {
    max-width: 360px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 8px;
}

.modal-head h3 {
    margin: 0;
    font-size: 16px;
}

.modal-body {
    padding: 6px 18px 18px;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.confirm-text {
    margin: 0 0 14px;
    color: var(--text-2);
    line-height: 1.6;
}

.confirm-extra {
    margin-bottom: 14px;
}

.confirm-extra label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
}

.drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
    padding: 0 14px 0 20px;
    border-bottom: 1px solid var(--border);
}

.drawer-head h3 {
    margin: 0;
    font-size: 16px;
}

.drawer-body {
    flex: 1;
    overflow: auto;
    padding: 16px;
}

.panel {
    margin-bottom: 22px;
}

.panel h4 {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--text-2);
    font-weight: 600;
}

.group-manage {
    margin-bottom: 10px;
}

.group-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    margin-bottom: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.group-row .g-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-row .g-count {
    font-size: 12px;
    color: var(--text-3);
}

.group-row button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.group-row button:hover {
    background: var(--border);
    color: var(--text);
}

.group-row button.danger:hover {
    color: var(--danger);
}

.inline-form {
    display: flex;
    gap: 8px;
}

.inline-form input {
    flex: 1;
}

.sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-lg);
    padding-bottom: env(safe-area-inset-bottom);
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 6px 20px;
}

.sheet-head h3 {
    margin: 0;
    font-size: 15px;
}

.sheet-body {
    overflow: auto;
    padding: 4px 12px 16px;
}

/* -------------------- 开关 -------------------- */

.switch {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-track {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 20px;
    background: var(--border);
    transition: background .16s;
    flex: 0 0 auto;
}

.switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .16s;
}

.switch input:checked + .switch-track {
    background: var(--primary);
}

.switch input:checked + .switch-track .switch-thumb {
    transform: translateX(18px);
}

/* -------------------- Toast -------------------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(28px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 90;
    max-width: 82vw;
    padding: 10px 18px;
    border-radius: 22px;
    background: rgba(24, 28, 34, .92);
    color: #fff;
    font-size: 13px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: toast-in .18s ease;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* ============================================================
   手机端
   ============================================================ */

@media (max-width: 860px) {
    .only-mobile {
        display: inline-flex !important;
    }

    .only-desktop {
        display: none !important;
    }

    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .tabbar {
        display: flex;
        gap: 8px;
        align-items: center;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        padding: 0 12px env(safe-area-inset-bottom);
        overflow-x: auto;
        background: var(--surface);
        border-top: 1px solid var(--border);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabbar::-webkit-scrollbar {
        display: none;
    }

    .tab {
        flex: 0 0 auto;
        height: 34px;
        padding: 0 14px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: var(--surface-2);
        color: var(--text-2);
        white-space: nowrap;
        cursor: pointer;
    }

    .tab.active {
        background: var(--primary);
        border-color: var(--primary);
        color: #fff;
        font-weight: 600;
    }

    .content {
        padding: 14px 14px 20px;
    }

    .grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .card {
        padding: 13px;
    }

    /* 手机上常驻显示操作按钮，因为没有 hover */
    .card-actions {
        position: static;
        opacity: 1;
        border: none;
        padding: 0;
        background: transparent;
        justify-content: flex-end;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px dashed var(--border);
    }

    .card-actions button {
        width: 40px;
        height: 34px;
    }

    .badge-top {
        top: 13px;
        right: 13px;
        bottom: auto;
    }

    .fab {
        display: inline-flex !important;
    }

    .topbar {
        padding: 0 12px;
        gap: 8px;
    }

    .drawer {
        max-width: none;
    }

    .modal {
        align-items: flex-end;
    }

    .modal-box {
        max-width: none;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .modal-small {
        margin: 0 0 0;
    }

    .toast {
        bottom: calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 380px) {
    .content-head h2 {
        font-size: 15px;
    }
}
