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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #ca8a04;
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* 导航 */
.nav {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary);
}

.nav-tabs {
    display: flex;
    gap: 4px;
}

.nav-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}

.nav-tab.active {
    background: var(--primary);
    color: white;
    font-weight: 500;
}

/* 页面 */
.main { padding: 12px; max-width: 720px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }

/* 卡片 */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

.card h2, .card h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-header h2 { margin-bottom: 0; }

/* 表单 */
.form-row {
    margin-bottom: 14px;
}

.form-row label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.form-row.inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-row.inline label {
    margin-bottom: 0;
}

input, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    background: var(--card);
}

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

.entity-input {
    display: flex;
    gap: 8px;
}

.entity-input select {
    flex: 1;
}

.entity-input input[type="text"] {
    flex: 1;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
    flex: 1;
}

/* 按钮 */
.btn-primary {
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

.btn-secondary {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
}

.btn-settle {
    background: var(--success);
    color: white;
}

/* 开关 */
.toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
}

.toggle input { width: auto; }

/* 列表 */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: 14px;
}

.list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.list-item-date {
    font-size: 12px;
    color: var(--text-muted);
}

.list-item-amount {
    font-weight: 600;
    font-size: 15px;
}

.list-item-desc {
    font-size: 13px;
    color: var(--text-muted);
}

.list-item-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

/* 分配面板 */
.alloc-summary {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
}

.alloc-summary strong { font-size: 15px; }

.alloc-list { display: flex; flex-direction: column; gap: 10px; }

.alloc-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.alloc-item-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
}

.alloc-item-info .remaining {
    color: var(--text-muted);
    font-size: 13px;
}

.alloc-item-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.alloc-item-input input {
    flex: 1;
}

/* 总览 */
.overview-section {
    margin-bottom: 16px;
}

.overview-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding: 0 4px;
}

.group-item {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 8px;
    overflow: hidden;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    background: var(--card);
    transition: background 0.2s;
}

.group-header:hover { background: #f9fafb; }

.group-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.group-arrow {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s;
    width: 16px;
    text-align: center;
}

.group-arrow.expanded { transform: rotate(90deg); }

.group-name {
    font-weight: 500;
    font-size: 15px;
}

.group-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.group-count {
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.group-amount {
    font-weight: 600;
    font-size: 15px;
    min-width: 100px;
    text-align: right;
}

.group-amount.receivable { color: var(--success); }
.group-amount.payable { color: var(--danger); }

.group-details {
    display: none;
    border-top: 1px solid var(--border);
    padding: 8px 16px;
}

.group-details.open { display: block; }

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.detail-row:last-child { border-bottom: none; }

.detail-row.selected {
    background: var(--primary);
    color: white;
    margin: 0 -12px;
    padding: 8px 12px;
    border-radius: var(--radius);
    border-bottom: none;
}

.detail-row.selected .detail-date,
.detail-row.selected .detail-desc {
    color: rgba(255,255,255,0.85);
}

.detail-row.selected .detail-amount {
    color: white;
}

.detail-info { flex: 1; }

.detail-date {
    font-size: 12px;
    color: var(--text-muted);
}

.detail-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.detail-amount {
    font-weight: 500;
    text-align: right;
    min-width: 80px;
}

.detail-actions {
    display: flex;
    gap: 6px;
    margin-left: 8px;
}

/* 净额汇总 */
.net-summary {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-top: 12px;
}

.net-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 14px;
}

.net-summary-row.total {
    border-top: 2px solid var(--border);
    margin-top: 8px;
    padding-top: 10px;
    font-size: 16px;
    font-weight: 600;
}

.net-positive { color: var(--success); }
.net-negative { color: var(--danger); }

/* 状态标签 */
.status-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.status-unpaid { background: #fee2e2; color: #991b1b; }
.status-partial { background: #fef3c7; color: #92400e; }
.status-settled { background: #dcfce7; color: #166534; }

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

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

/* 特殊挂账红色竖条标记 */
.special-mark {
    position: relative;
}

.special-mark::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 4px;
    background: var(--danger);
    border-radius: 2px;
}

.list-item.special-mark {
    padding-left: 20px;
}

.detail-row.special-mark {
    padding-left: 12px;
}

.detail-row.special-mark.selected {
    padding-left: 12px;
}

/* 结算历史小标签 */
.settle-tag {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
    background: #e0e7ff;
    color: #3730a3;
    margin-left: 6px;
}

/* 结算模式选择 */
.mode-select {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.mode-option:hover {
    background: #f9fafb;
}

.mode-option input {
    width: auto;
    flex-shrink: 0;
}

/* 分配面板 - 记录项（合并/单独共用） */
.alloc-record-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}

.alloc-record-item.reverse {
    background: #fef2f2;
    border-color: #fecaca;
}

.alloc-record-item.reverse .reverse-label {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: #fee2e2;
    color: #991b1b;
    margin-left: 8px;
    font-weight: 500;
}

.alloc-record-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.alloc-record-header input[type="checkbox"],
.alloc-record-header input[type="radio"] {
    width: auto;
    flex-shrink: 0;
    margin-top: 2px;
}

.alloc-record-info {
    flex: 1;
    font-size: 14px;
}

.alloc-record-meta {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.alloc-record-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 24px;
}

.alloc-record-input input[type="number"] {
    flex: 1;
}

.alloc-record-input .max-btn {
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    white-space: nowrap;
}

/* 记录列表中的结算输入 */
.settle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    border-top: 1px solid var(--border);
    padding: 8px 0;
    margin-top: 0;
}

.settle-row input[type="checkbox"] {
    width: auto;
    flex-shrink: 0;
}

.settle-row label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.settle-expandable {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transition: grid-template-rows 0.3s ease, opacity 0.3s ease;
    width: 100%;
}

.settle-expandable.visible {
    grid-template-rows: 1fr;
    opacity: 1;
}

.settle-expandable-inner {
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 8px;
}

.settle-amt {
    width: 100px;
    padding: 6px 8px;
    font-size: 14px;
}

.settle-cmt {
    flex: 1;
    padding: 6px 8px;
    font-size: 14px;
}

/* 确认对话框 */
.confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-modal.hidden {
    display: none !important;
}

.confirm-modal .card {
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    margin: 0;
}

.confirm-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.confirm-item:last-child {
    border-bottom: none;
}

.confirm-net-change {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 12px;
    margin: 12px 0;
    font-size: 14px;
}

/* 响应式 */
@media (min-width: 640px) {
    .nav { padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; }
    .nav-brand { margin-bottom: 0; }
    .nav-tabs { width: auto; }
    .main { padding: 20px; }
    .card { padding: 20px; }
}
