:root {
    --bg: #ffffff;
    --page: #f7f8fa;
    --control: #f1f3f5;
    --divider: #edeff2;
    --primary: #2f80ff;
    --primary-hover: #1f6fea;
    --text: #111827;
    --muted: #6b7280;
    --folder: #ffc83d;
    --danger: #dc2626;
    --success: #16803a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
}

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

input,
select,
button {
    font: inherit;
}

.topbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 32px;
    border-bottom: 1px solid var(--divider);
    background: var(--bg);
}

.brand,
.top-actions,
.table-name,
.row-actions,
.form-actions,
.section-heading {
    display: flex;
    align-items: center;
}

.brand {
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
}

.top-actions {
    gap: 18px;
}

.workspace {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 32px 48px;
}

.nav-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 14px 0 12px;
    border-bottom: 1px solid var(--divider);
}

.tabs {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px 22px;
    min-width: 0;
    max-width: calc(100% - 390px);
    overflow: visible;
    scrollbar-width: none;
}

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

.tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    height: 38px;
    color: var(--text);
    white-space: nowrap;
}

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

.tab.active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px;
}

.search {
    flex: 0 0 360px;
    width: min(360px, 40vw);
    height: 38px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--control);
    color: var(--muted);
}

.search input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.search-icon {
    position: relative;
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
}

.search-icon::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 8px;
    height: 8px;
    border: 1.8px solid currentColor;
    border-radius: 50%;
}

.search-icon::after {
    content: "";
    position: absolute;
    left: 10px;
    top: 11px;
    width: 6px;
    height: 1.8px;
    border-radius: 2px;
    background: currentColor;
    transform: rotate(45deg);
    transform-origin: left center;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 76px;
}

.toolbar h1 {
    margin: 0;
    font-size: 20px;
}

.toolbar p {
    margin: 6px 0 0;
    color: var(--muted);
}

.link-section {
    margin-top: 18px;
}

.section-heading {
    gap: 8px;
    height: 40px;
    color: var(--muted);
}

.section-heading h2 {
    margin: 0;
    color: var(--text);
    font-size: 15px;
}

.folder-icon {
    width: 18px;
    height: 14px;
    display: inline-block;
    position: relative;
    flex: 0 0 18px;
    color: var(--folder);
    background: currentColor;
    border-radius: 3px;
}

.folder-icon::before {
    content: "";
    position: absolute;
    left: 1px;
    top: -4px;
    width: 8px;
    height: 5px;
    background: currentColor;
    border-radius: 3px 3px 0 0;
}

.link-list,
.table-wrap,
.editor-form,
.empty-state,
.login-panel {
    border-top: 1px solid var(--divider);
}

.link-row {
    min-height: 66px;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) minmax(120px, auto);
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--divider);
    background: #fff;
}

.link-row:hover,
tbody tr:hover {
    background: var(--page);
}

.link-icon {
    position: relative;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--control);
    color: var(--primary);
    font-size: 15px;
}

.default-link-icon::before {
    content: "";
    width: 9px;
    height: 9px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    transform: rotate(45deg);
}

.default-link-icon::after {
    content: "";
    position: absolute;
    width: 11px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transform: translateX(-1px);
}

.link-icon.small {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
}

.link-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.link-main strong,
.table-name strong {
    font-weight: 600;
}

.link-main small,
.table-name small {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-host {
    color: var(--muted);
    text-align: right;
}

.empty-state {
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--muted);
    border-bottom: 1px solid var(--divider);
}

.empty-state strong {
    color: var(--text);
}

.text-link {
    color: var(--primary);
}

.text-link:hover {
    color: var(--primary-hover);
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--page);
    padding: 24px;
}

.login-panel {
    width: min(420px, 100%);
    padding: 28px;
    border: 1px solid var(--divider);
    border-radius: 8px;
    background: #fff;
}

.login-brand {
    margin-bottom: 24px;
}

.login-panel h1 {
    margin: 0 0 18px;
    font-size: 20px;
}

.form-stack,
.editor-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.editor-form {
    margin-bottom: 24px;
    padding: 18px 0 20px;
    border-bottom: 1px solid var(--divider);
}

.compact-form {
    max-width: 520px;
}

.form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

label span {
    color: var(--muted);
    font-size: 13px;
}

input,
select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--divider);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    outline: 0;
}

input:focus,
select:focus {
    border-color: var(--primary);
}

.btn,
.link-button {
    border: 0;
    cursor: pointer;
}

.btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    border-radius: 999px;
    font-weight: 600;
}

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

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

.btn.secondary {
    background: var(--control);
    color: var(--text);
}

.alert {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--control);
}

.alert.success {
    color: var(--success);
}

.alert.error {
    color: var(--danger);
}

.admin-grid {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 32px;
}

.admin-sidebar {
    padding-top: 10px;
}

.side-link {
    height: 38px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--muted);
}

.side-link.active,
.side-link:hover {
    background: var(--control);
    color: var(--primary);
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    height: 58px;
    padding: 0 12px;
    border-bottom: 1px solid var(--divider);
    text-align: left;
    vertical-align: middle;
}

th {
    height: 42px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.table-name {
    gap: 10px;
    min-width: 0;
}

.table-name > span:last-child {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.actions-col {
    width: 150px;
}

.row-actions {
    gap: 12px;
}

.row-actions form {
    margin: 0;
}

.link-button {
    padding: 0;
    background: transparent;
    color: var(--primary);
}

.link-button.danger {
    color: var(--danger);
}

.empty-cell {
    color: var(--muted);
    text-align: center;
}

@media (max-width: 760px) {
    .topbar {
        padding: 0 18px;
    }

    .workspace {
        padding: 18px 18px 36px;
    }

    .nav-row {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        padding-bottom: 14px;
    }

    .tabs {
        max-width: 100%;
        gap: 8px 18px;
    }

    .search {
        flex-basis: auto;
        width: 100%;
    }

    .toolbar {
        min-height: 66px;
    }

    .link-row {
        grid-template-columns: 38px minmax(0, 1fr);
    }

    .link-host {
        display: none;
    }

    .admin-grid,
    .form-row {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        display: flex;
        gap: 8px;
        padding-top: 0;
    }

    .side-link {
        flex: 1;
        justify-content: center;
    }
}
