:root {
    --primary: #ff4757;
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-main: #2f3542;
    --text-sub: #747d8c;
    --border: #dfe4ea;
    --female-color: #ff7f50;
    --male-color: #1e90ff;
    --tab-height: 60px;
    --header-height: 50px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }

body { 
    background-color: #e0e0e0; 
    display: flex; 
    justify-content: center; 
    height: 100vh; 
    height: 100dvh; 
    overflow: hidden; 
}

#app-container {
    width: 100%;
    max-width: 430px;
    height: 100%;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

.header {
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-height) + env(safe-area-inset-top));
}

.header-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

.header-btn-left, .header-btn-right {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    z-index: 10;
    margin-top: env(safe-area-inset-top);
}

.header-btn-left { color: var(--primary); cursor: pointer; }
.header-btn-right { justify-content: flex-end; margin-left: auto; }

.btn-inner {
    background: var(--primary);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.header-btn-right.disabled .btn-inner {
    background: #dfe4ea !important;
    color: #a4b0be !important;
    pointer-events: none;
}
.header-btn-right.blue-btn .btn-inner {
    background: var(--male-color);
}

.page {
    position: absolute;
    top: calc(var(--header-height) + env(safe-area-inset-top));
    bottom: calc(var(--tab-height) + env(safe-area-inset-bottom));
    left: 0; right: 0;
    overflow-y: auto;
    background: var(--bg-color);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 10;
}
.page.active { transform: translateX(0); }
.page.full-page { bottom: 0; z-index: 200; top: 0; padding-bottom: env(safe-area-inset-bottom); }
.page.full-page .page-content { padding-top: calc(var(--header-height) + env(safe-area-inset-top)); }

#login-page { display: flex; flex-direction: column; justify-content: center; align-items: center; bottom: 0; top:0; z-index: 300; background: #fff;}
.login-btn { padding: 12px 30px; background: var(--primary); color: white; border-radius: 25px; font-size: 1.1rem; cursor: pointer; margin-top: 20px;}

.love-container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; padding: 20px; text-align: center; }
.love-title { font-size: 1.2rem; color: var(--text-sub); margin-bottom: 10px; }
.love-timer { font-size: 1.8rem; font-weight: 700; color: var(--primary); background: white; padding: 20px; border-radius: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); cursor: pointer; user-select: none; width: 100%;}
.love-timer span { font-size: 1rem; color: var(--text-sub); font-weight: 400;}

.tabs { display: flex; background: white; border-bottom: 1px solid var(--border); }
.tab-item { flex: 1; text-align: center; padding: 12px 0; font-size: 1rem; color: var(--text-sub); cursor: pointer; position: relative; }
.tab-item.active-female { color: var(--female-color); font-weight: 600; }
.tab-item.active-male { color: var(--male-color); font-weight: 600; }
.tab-item.active-female::after { content: ''; position: absolute; bottom: 0; left: 20%; right: 20%; height: 3px; background: var(--female-color); border-radius: 3px 3px 0 0; }
.tab-item.active-male::after { content: ''; position: absolute; bottom: 0; left: 20%; right: 20%; height: 3px; background: var(--male-color); border-radius: 3px 3px 0 0; }

.total-time-module { text-align: center; padding: 20px 0; background: var(--bg-color); }
.total-time-value { font-size: 2rem; font-weight: bold; color: var(--text-main); }
.total-time-label { font-size: 0.85rem; color: var(--text-sub); }

.record-list { padding: 10px 15px; padding-bottom: 120px; }
.record-item { background: var(--card-bg); border-radius: 10px; padding: 15px; margin-bottom: 12px; display: flex; justify-content: space-between; box-shadow: 0 2px 8px rgba(0,0,0,0.03); cursor: pointer;}
.record-left { display: flex; flex-direction: column; justify-content: center; }
.record-title { font-size: 1.05rem; font-weight: 500; color: var(--text-main); margin-bottom: 5px; }
.record-date { font-size: 0.8rem; color: var(--text-sub); }
.record-duration { font-size: 1.1rem; font-weight: 600; color: var(--primary); display: flex; align-items: center;}

.record-item.used {
    background: #f4f6f9;
    box-shadow: none;
    border: 1px dashed #ced6e0;
}
.record-item.used .record-title,
.record-item.used .record-date,
.record-item.used .record-duration {
    text-decoration: line-through;
    color: #a4b0be;
}

.empty-state { text-align: center; color: var(--text-sub); padding-top: 50px; font-size: 0.95rem; }

.fab-container {
    position: absolute;
    bottom: calc(var(--tab-height) + env(safe-area-inset-bottom) + 20px);
    right: 20px;
    display: none; 
    flex-direction: column;
    gap: 15px;
    z-index: 101;
}
.fab {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: transform 0.1s;
}
.fab:active { transform: scale(0.95); }
.fab-add { background: var(--primary); box-shadow: 0 4px 10px rgba(255, 71, 87, 0.4); }
.fab-minus { background: var(--male-color); font-size: 2.5rem; box-shadow: 0 4px 10px rgba(30, 144, 255, 0.4); }

.form-group { background: white; margin-bottom: 10px; padding: 0 15px; }
.form-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: 15px 0; }
.form-row:last-child { border-bottom: none; }
.form-label { width: 75px; font-size: 1rem; color: var(--text-main); flex-shrink: 0;}
.form-input { flex: 1; border: none; outline: none; font-size: 1rem; color: var(--text-main); background: transparent; }

.form-time-inputs { display: flex; flex: 1; gap: 10px; align-items: center; }
.time-input { flex: 1; min-width: 0; width: 100%; text-align: center; border: 1px solid var(--border); border-radius: 5px; padding: 10px 5px; font-size: 1rem; outline: none; }

.form-textarea { width: 100%; border: none; outline: none; font-size: 1rem; color: var(--text-main); resize: none; padding: 15px 0; min-height: 150px; }

.bottom-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--tab-height) + env(safe-area-inset-bottom));
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-sub);
    cursor: pointer;
    font-size: 0.75rem;
    text-align: center;
    width: 33.33%; 
    height: var(--tab-height);
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 1.4rem; margin-bottom: 2px; }

#toast {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 12px 24px;
    border-radius: 20px;
    font-size: 0.95rem;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
#toast.show { opacity: 1; }

/* === 家规专属样式 === */
.rule-item {
    background: var(--card-bg); 
    border-radius: 10px; 
    padding: 15px; 
    margin-bottom: 12px; 
    display: flex; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.03); 
    cursor: pointer;
    align-items: flex-start;
}
.rule-index {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--primary);
    margin-right: 8px;
    white-space: nowrap; 
}
.rule-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.rule-title-text {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 8px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap; 
}
.rule-date {
    font-size: 0.8rem;
    color: var(--text-sub);
}
/* === 删除按钮全局样式 === */
.delete-btn {
    background: #ff4757;
    color: white;
    text-align: center;
    padding: 15px;
    border-radius: 10px;
    margin: 20px 15px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 71, 87, 0.3);
    transition: all 0.2s;
}
.delete-btn:active { transform: scale(0.98); }

/* === 弹窗菜单 Popover === */
.popover-menu {
    position: absolute; top: calc(var(--header-height) + env(safe-area-inset-top) + 5px); right: 15px;
    background: var(--card-bg); border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    z-index: 200; display: none; flex-direction: column; overflow: hidden;
}
.popover-menu.show { display: flex; animation: fadeInDown 0.2s ease; }
.popover-item { padding: 12px 20px; border-bottom: 1px solid var(--border); font-size: 1rem; color: var(--text-main); }
.popover-item:last-child { border-bottom: none; }
.popover-item:active { background: var(--bg-color); }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* === 分类折叠标题 === */
.category-wrapper { margin-bottom: 15px; }
.category-header {
    background: #eef2f5; border-radius: 8px; padding: 10px 15px; font-weight: bold; color: var(--text-sub);
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; cursor: pointer;
}
.category-header::after { content: '▼'; transition: transform 0.2s; }
.category-wrapper.collapsed .category-header::after { transform: rotate(-90deg); }
.category-wrapper.collapsed .rule-item { display: none !important; }

/* === CSS 原生滑动菜单 (极客黑科技) === */
.swipe-wrap {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
    border-bottom: 1px solid var(--border); background: white; margin-bottom: 1px;
}
.swipe-wrap::-webkit-scrollbar { display: none; }
.swipe-content { flex: 0 0 100%; scroll-snap-align: start; padding: 15px; display: flex; align-items: center; }
.swipe-actions { flex: 0 0 140px; scroll-snap-align: end; display: flex; }
.swipe-btn { flex: 1; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 0.9rem;}
.swipe-edit { background: var(--male-color); }
.swipe-del { background: var(--primary); }
.cat-radio { transform: scale(1.3); margin-right: 15px; accent-color: var(--primary); }

/* === 箭头排序交互 === */
.sort-arrows { display: none; flex-direction: column; align-items: center; justify-content: center; padding: 0 15px 0 5px; color: var(--text-sub); font-size: 1.2rem; font-weight: bold; }
.sorting-mode .sort-arrows { display: flex; }
.sorting-mode .rule-item { box-shadow: 0 0 0 1px var(--primary); align-items: center; }
.sorting-mode .rule-item .rule-date { display: none; }
.sort-up, .sort-down { padding: 2px 10px; line-height: 1; cursor: pointer; transition: transform 0.1s; }
.sort-up:active, .sort-down:active { transform: scale(1.3); color: var(--primary); }