:root {
    --bg: #f5f0eb;
    --card-bg: #fffcf8;
    --primary: #8B7355;
    --primary-dark: #6d5942;
    --accent: #c0392b;
    --text: #4a3728;
    --text-dim: #8b7d6b;
    --border: #e8ddd0;
    --shadow: rgba(139, 115, 85, 0.1);
    --radius: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, 'Microsoft YaHei', 'PingFang SC', sans-serif;
    background: var(--bg); color: var(--text); min-height: 100vh;
}
.container { max-width: 800px; margin: 0 auto; padding: 20px 16px; }
.card {
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: 0 2px 12px var(--shadow); padding: 24px;
    border: 1px solid var(--border); margin-bottom: 16px;
}
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; border-radius: 8px; border: none;
    font-size: 14px; cursor: pointer; font-family: inherit;
    text-decoration: none; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-danger { background: var(--accent); color: #fff; }
.btn-danger:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-outline {
    background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
input, textarea, select {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; font-family: inherit;
    background: var(--card-bg); color: var(--text); outline: none;
    transition: border-color 0.2s;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 120px; }
.header {
    background: var(--card-bg); border-bottom: 1px solid var(--border);
    padding: 12px 0; position: sticky; top: 0; z-index: 100;
}
.header-inner {
    max-width: 800px; margin: 0 auto; padding: 0 16px;
    display: flex; align-items: center; justify-content: space-between;
    position: relative;
}
.header .logo { font-size: 20px; font-weight: 700; color: var(--primary); text-decoration: none; }
.home-link{font-size:20px;margin-right:8px;opacity:0.5;text-decoration:none;color:var(--primary);transition:opacity .3s}
.home-link:hover{opacity:1}
.header .logo span { color: var(--accent); }
.nav { display: flex; gap: 8px; align-items: center; }
.nav a {
    padding: 6px 14px; border-radius: 6px; text-decoration: none;
    color: var(--text-dim); font-size: 14px; transition: all 0.2s;
}
.nav a:hover, .nav a.active { background: var(--bg); color: var(--primary); }
.nav .user-name { color: var(--primary); font-weight: 600; font-size: 14px; }
.mobile-menu-btn { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--primary); }
@media (max-width: 640px) {
    .mobile-menu-btn { display: block; }
    .nav { display: none; position: absolute; top: 100%; left: 0; right: 0;
        background: var(--card-bg); border-bottom: 1px solid var(--border);
        padding: 12px 16px; flex-direction: column;
        box-shadow: 0 4px 12px var(--shadow); }
    .nav.open { display: flex; }
    .nav a { width: 100%; padding: 12px 14px; font-size: 15px; }
    .nav .user-name { padding: 8px 14px; }
    .container { padding: 10px; }
    .card { padding: 14px; }
    .header-inner { padding: 0 12px; }
    .header .logo { font-size: 18px; }
    
    /* Touch-friendly buttons */
    .btn { padding: 12px 18px; font-size: 15px; min-height: 44px; }
    .btn-outline { width: 100%; justify-content: center; }
    
    /* Larger form inputs for touch */
    input, textarea, select { padding: 12px 14px; font-size: 16px; }
    
    /* Letter list */
    .letter-item { padding: 12px 12px; }
    .letter-avatar { width: 36px; height: 36px; font-size: 14px; margin-right: 10px; }
    .letter-info .title { font-size: 14px; }
    .letter-time { font-size: 11px; }
    
    /* Admin table -> stacked cards */
    table { display: block; }
    table thead { display: none; }
    table tbody, table tr { display: block; width: 100%; }
    table tr {
        padding: 12px; margin-bottom: 8px;
        background: var(--bg); border-radius: 8px;
        border: 1px solid var(--border);
    }
    table td {
        display: flex; justify-content: space-between; padding: 6px 0;
        border: none; font-size: 14px;
    }
    table td:before {
        content: attr(data-label);
        font-weight: 600; color: var(--text-dim); font-size: 12px;
    }
    
    /* Stats grid */
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stats-grid > div { padding: 12px 8px; }
    .stats-grid > div > div:first-child { font-size: 22px; }
    
    /* Empty state */
    .empty-state { padding: 32px 16px; }
    .empty-state .icon { font-size: 40px; }
}
.letter-list { list-style: none; }
.letter-item {
    display: flex; align-items: center; padding: 14px 16px;
    border-bottom: 1px solid var(--border); cursor: pointer;
    transition: background 0.2s; text-decoration: none; color: var(--text);
}
.letter-item:hover { background: rgba(139, 115, 85, 0.04); }
.letter-item:last-child { border-bottom: none; }
.letter-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary); color: #fff; display: flex;
    align-items: center; justify-content: center; font-size: 16px;
    margin-right: 14px; flex-shrink: 0;
}
.letter-info { flex: 1; min-width: 0; }
.letter-info .title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.letter-info .meta { font-size: 12px; color: var(--text-dim); }
.letter-time { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-dim); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.error { background: #fef2f2; color: #dc2626; padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.success { background: #f0fdf4; color: #16a34a; padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }

/* Mode selector: stack vertically on mobile */
@media (max-width: 640px) {
    .mode-selector { flex-direction: column !important; }
    .mode-selector label { width: 100% !important; }
    
    /* Admin table cell stacking fix */
    table td[data-label] { display: flex; justify-content: space-between; padding: 8px 4px; }
    table td[data-label]::before {
        content: attr(data-label);
        font-weight: 600; color: var(--text-dim); font-size: 12px;
        white-space: nowrap; margin-right: 8px;
    }
    /* Action td: don't repeat the label when flex-wrap already shows buttons */
    td[data-label="操作"] { flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
    td[data-label="操作"]::before { align-self: center; }
    
    /* Claim code display on mobile */
    .claim-code { font-size: 16px !important; letter-spacing: 2px !important; word-break: break-all; }
    
    /* Read page adjustments */
    .read-header { flex-direction: column; gap: 8px; align-items: flex-start !important; }
    
    /* Inbox header buttons */
    .inbox-header { flex-direction: column; gap: 10px; align-items: stretch !important; }
    .inbox-header .btn-group { display: flex; gap: 8px; }
    .inbox-header .btn-group .btn { flex: 1; justify-content: center; }
}

/* Mode card selector */
.mode-card {
    flex: 1; padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px; text-align: center;
    cursor: pointer; transition: all 0.2s;
}
.mode-card:hover { border-color: var(--primary); background: rgba(139,115,85,0.04); }
.mode-card.active {
    border-color: var(--primary) !important;
    background: rgba(139,115,85,0.08);
    box-shadow: 0 2px 8px var(--shadow);
}
@media (max-width: 640px) {
    .mode-card { width: 100% !important; flex: none !important; }
}

.user-cid { font-size:11px;color:var(--text-dim);font-family:monospace;margin-left:4px; }
@media (max-width:640px) { .user-cid { display:none; } }


/* Privacy checkboxes */
.privacy-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.privacy-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.privacy-row:first-child {
    border-top: 1px solid var(--border);
}
.privacy-row:active {
    background: var(--bg);
}
.privacy-row input {
    display: none;
}
.privacy-check {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 5px;
    flex-shrink: 0;
    position: relative;
    transition: all 0.15s;
}
.privacy-row input:checked + .privacy-check {
    background: var(--primary);
    border-color: var(--primary);
}
.privacy-row input:checked + .privacy-check::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 6px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.privacy-label {
    font-size: 14px;
    color: var(--text);
}
