/* ==========================================================================
   components.css - 组件样式
   按钮 / 输入框 / 卡片 / 表格 / Toast / 弹窗 / 侧边栏 / Tab / 拖拽上传 等
   ========================================================================== */

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--c-surface-2);
    color: var(--c-text);
    transition: background var(--t-fast), border-color var(--t-fast),
                transform var(--t-fast), opacity var(--t-fast);
    user-select: none;
    white-space: nowrap;
}

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

.btn:active {
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
}

.btn:disabled,
.btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn svg {
    width: 16px;
    height: 16px;
}

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

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

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

.btn--danger:hover {
    background: #e64a68;
}

.btn--ghost {
    background: transparent;
    border-color: var(--c-border);
    color: var(--c-text-muted);
}

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

.btn--sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn--lg {
    padding: 12px 24px;
    font-size: 1.05rem;
}

.btn--block {
    width: 100%;
}

.btn--icon {
    padding: 8px;
    width: 36px;
    height: 36px;
}

/* 按钮内 loading spinner */
.btn .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.btn--ghost .spinner {
    border-color: rgba(138, 147, 166, 0.4);
    border-top-color: var(--c-text-muted);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- 输入框 ---------- */
.input,
.textarea,
.select {
    width: 100%;
    padding: 10px 12px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    color: var(--c-text);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.input::placeholder,
.textarea::placeholder {
    color: var(--c-text-muted);
    opacity: 0.7;
}

.input:focus,
.textarea:focus,
.select:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.18);
}

.input.is-invalid {
    border-color: var(--c-danger);
}

.textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.5;
}

.select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%238a93a6' d='M6 8.5L1.5 4h9z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.select option {
    background: var(--c-surface);
    color: var(--c-text);
}

/* 输入框组（带右侧按钮） */
.input-group {
    position: relative;
    display: flex;
    align-items: stretch;
}

.input-group .input {
    padding-right: 44px;
}

.input-group__toggle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--c-text-muted);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    transition: color var(--t-fast);
}

.input-group__toggle:hover {
    color: var(--c-text);
}

.input-group__toggle svg {
    width: 18px;
    height: 18px;
}

/* 字符计数 */
.field-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--c-text-muted);
}

/* ---------- 卡片 ---------- */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: var(--gap-lg);
    box-shadow: var(--shadow-sm);
}

.card--padded {
    padding: var(--gap-lg);
}

.card--flush {
    padding: 0;
    overflow: hidden;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    padding: var(--gap) var(--gap-lg);
    border-bottom: 1px solid var(--c-border);
}

.card__title {
    font-size: 1.05rem;
    font-weight: 600;
}

.card__body {
    padding: var(--gap-lg);
}

.card__footer {
    padding: var(--gap) var(--gap-lg);
    border-top: 1px solid var(--c-border);
    background: rgba(0, 0, 0, 0.15);
}

/* 登录/注册卡片 */
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: var(--gap-lg);
    box-shadow: var(--shadow-lg);
}

.auth-card__footer {
    margin-top: var(--gap-lg);
    padding-top: var(--gap);
    border-top: 1px solid var(--c-border);
    text-align: center;
    font-size: 0.9rem;
    color: var(--c-text-muted);
}

.auth-card__footer a {
    font-weight: 600;
}

/* ---------- 表格 ---------- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 12px var(--gap);
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--c-border);
}

.table thead th {
    background: var(--c-surface-2);
    color: var(--c-text-muted);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
    z-index: 1;
}

.table tbody tr {
    transition: background var(--t-fast);
}

.table tbody tr:hover {
    background: rgba(79, 124, 255, 0.06);
}

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

.table tr.is-expandable {
    cursor: pointer;
}

.table .row-detail {
    background: var(--c-bg);
}

.table .row-detail td {
    padding: var(--gap);
}

.table .col-id {
    color: var(--c-text-muted);
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

/* 空状态 */
.empty-state {
    padding: var(--gap-lg) * 2;
    text-align: center;
    color: var(--c-text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--gap);
    opacity: 0.4;
}

/* ---------- 标签 / 徽章 ---------- */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 999px;
    background: var(--c-surface-2);
    color: var(--c-text-muted);
    border: 1px solid var(--c-border);
}

.tag--encrypt {
    background: rgba(79, 124, 255, 0.15);
    color: var(--c-primary);
    border-color: rgba(79, 124, 255, 0.35);
}

.tag--decrypt {
    background: rgba(45, 212, 164, 0.15);
    color: var(--c-success);
    border-color: rgba(45, 212, 164, 0.35);
}

.tag--success {
    background: rgba(45, 212, 164, 0.15);
    color: var(--c-success);
    border-color: rgba(45, 212, 164, 0.35);
}

.tag--danger {
    background: rgba(255, 92, 122, 0.15);
    color: var(--c-danger);
    border-color: rgba(255, 92, 122, 0.35);
}

.tag--warning {
    background: rgba(246, 183, 60, 0.15);
    color: var(--c-warning);
    border-color: rgba(246, 183, 60, 0.35);
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: calc(100vw - 40px);
}

.toast {
    pointer-events: auto;
    min-width: 240px;
    max-width: 360px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-left: 4px solid var(--c-primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    color: var(--c-text);
    font-size: 0.9rem;
    animation: toast-in 0.25s ease;
}

.toast.is-leaving {
    animation: toast-out 0.25s ease forwards;
}

.toast__icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.toast__msg {
    flex: 1;
    word-break: break-word;
}

.toast--success { border-left-color: var(--c-success); }
.toast--success .toast__icon { color: var(--c-success); }
.toast--error   { border-left-color: var(--c-danger); }
.toast--error .toast__icon   { color: var(--c-danger); }
.toast--warning { border-left-color: var(--c-warning); }
.toast--warning .toast__icon { color: var(--c-warning); }
.toast--info    { border-left-color: var(--c-primary); }
.toast--info .toast__icon    { color: var(--c-primary); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(20px); }
}

/* ---------- 弹窗（模态框） ---------- */
.modal-mask {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gap);
    animation: fade-in 0.2s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    width: 100%;
    max-width: 520px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modal-in 0.25s ease;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--gap) var(--gap-lg);
    border-bottom: 1px solid var(--c-border);
}

.modal__title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal__close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--c-text-muted);
    transition: background var(--t-fast), color var(--t-fast);
}

.modal__close:hover {
    background: var(--c-surface-2);
    color: var(--c-text);
}

.modal__close svg {
    width: 18px;
    height: 18px;
}

.modal__body {
    padding: var(--gap-lg);
    overflow-y: auto;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: var(--gap) var(--gap-lg);
    border-top: 1px solid var(--c-border);
    background: rgba(0, 0, 0, 0.15);
}

/* ---------- Tab 切换 ---------- */
.tabs {
    display: inline-flex;
    gap: 2px;
    padding: 4px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
}

.tabs__item {
    padding: 8px 18px;
    border: none;
    background: transparent;
    color: var(--c-text-muted);
    font-size: 0.92rem;
    font-weight: 500;
    border-radius: 4px;
    transition: background var(--t-fast), color var(--t-fast);
}

.tabs__item:hover {
    color: var(--c-text);
}

.tabs__item.is-active {
    background: var(--c-primary);
    color: #fff;
}

/* 大尺寸 Tab（操作模式切换） */
.tabs--lg .tabs__item {
    padding: 10px 24px;
    font-size: 1rem;
}

/* ---------- 筛选区 ---------- */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--gap);
    align-items: end;
    margin-bottom: var(--gap-lg);
}

.filter-bar__actions {
    display: flex;
    gap: 10px;
    align-items: end;
}

/* ---------- 分页 ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: var(--gap-lg);
    flex-wrap: wrap;
}

.pagination__btn,
.pagination__page {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    color: var(--c-text-muted);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

.pagination__btn:hover:not(:disabled),
.pagination__page:hover:not(.is-active) {
    background: var(--c-surface-2);
    color: var(--c-text);
}

.pagination__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

.pagination__ellipsis {
    padding: 0 4px;
    color: var(--c-text-muted);
}

.pagination__info {
    margin-left: var(--gap);
    color: var(--c-text-muted);
    font-size: 0.85rem;
}

/* ---------- 拖拽上传区 ---------- */
.dropzone {
    border: 2px dashed var(--c-border);
    border-radius: var(--radius);
    padding: var(--gap-lg) var(--gap);
    text-align: center;
    color: var(--c-text-muted);
    transition: border-color var(--t-fast), background var(--t-fast);
    cursor: pointer;
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--c-primary);
    background: rgba(79, 124, 255, 0.06);
    color: var(--c-text);
}

.dropzone svg {
    width: 40px;
    height: 40px;
    margin: 0 auto var(--gap);
    opacity: 0.6;
}

.dropzone__text {
    font-size: 0.95rem;
}

.dropzone__hint {
    font-size: 0.8rem;
    margin-top: 6px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: var(--gap);
    padding: 10px 12px;
    background: var(--c-surface-2);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
}

.file-info__name {
    flex: 1;
    word-break: break-all;
}

.file-info__size {
    color: var(--c-text-muted);
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

.file-info__remove {
    background: transparent;
    border: none;
    color: var(--c-text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color var(--t-fast);
}

.file-info__remove:hover {
    color: var(--c-danger);
}

/* ---------- 结果区 ---------- */
.result-box {
    position: relative;
}

.result-box textarea {
    width: 100%;
    min-height: 160px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--c-text);
    resize: vertical;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
    margin-top: var(--gap);
    padding: var(--gap);
    background: var(--c-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
    font-size: 0.85rem;
}

.result-meta__item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.result-meta__label {
    color: var(--c-text-muted);
    font-size: 0.78rem;
}

.result-meta__value {
    font-family: var(--font-mono);
    font-weight: 600;
}

.result-actions {
    display: flex;
    gap: 10px;
    margin-top: var(--gap);
    flex-wrap: wrap;
}

/* ---------- 算法说明 ---------- */
.algo-desc {
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(79, 124, 255, 0.08);
    border-left: 3px solid var(--c-primary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--c-text-muted);
}

/* ---------- 密码强度条 ---------- */
.strength {
    margin-top: 8px;
}

.strength__bar {
    height: 6px;
    background: var(--c-bg);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid var(--c-border);
}

.strength__fill {
    height: 100%;
    width: 0;
    transition: width var(--t), background var(--t);
    border-radius: 3px;
}

.strength__fill.weak    { width: 33%; background: var(--c-danger); }
.strength__fill.medium  { width: 66%; background: var(--c-warning); }
.strength__fill.strong  { width: 100%; background: var(--c-success); }

.strength__label {
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--c-text-muted);
}

/* ---------- loading 覆盖层 ---------- */
.loading-overlay {
    position: relative;
}

.loading-overlay::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 32, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    border-radius: inherit;
}

.btn .spinner-overlay {
    display: inline-block;
}

/* 章节标题 */
.section-title {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--c-text-muted);
    font-weight: 600;
    margin-bottom: var(--gap);
}

/* 网格 */
.grid {
    display: grid;
    gap: var(--gap-lg);
}

.grid--2 {
    grid-template-columns: repeat(2, 1fr);
}

/* 隐藏辅助类 */
.hidden {
    display: none !important;
}

/* 行内操作组 */
.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* 切换开关 */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

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

.switch__slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--c-border);
    border-radius: 22px;
    transition: background var(--t-fast);
}

.switch__slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--c-text);
    border-radius: 50%;
    transition: transform var(--t-fast);
}

.switch input:checked + .switch__slider {
    background: var(--c-success);
}

.switch input:checked + .switch__slider::before {
    transform: translateX(18px);
}

.switch input:focus-visible + .switch__slider {
    box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.3);
}

/* ---------- 历史详情展开网格 ---------- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--gap);
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
}

.detail-item--wide {
    grid-column: 1 / -1;
}

.detail-label {
    font-size: 0.75rem;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.detail-value {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    word-break: break-all;
}

/* 摘要单元格省略 */
.cell-summary {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--c-text-muted);
}

/* ---------- 加载遮罩（块级） ---------- */
.loading-block {
    position: relative;
    min-height: 120px;
}

.loading-block::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 32, 0.6) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'><circle cx='14' cy='14' r='10' fill='none' stroke='%234f7cff' stroke-width='3' stroke-dasharray='47 16' stroke-linecap='round'><animateTransform attributeName='transform' type='rotate' from='0 14 14' to='360 14 14' dur='0.8s' repeatCount='indefinite'/></circle></svg>") center / 28px no-repeat;
    z-index: 5;
    border-radius: inherit;
}

/* 行内 spinner（独立使用） */
.spinner-inline {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(138, 147, 166, 0.3);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
