:root {
    --primary: #4CAF50;
    --primary-dark: #388E3C;
    --accent: #FF9800;
    --bg: #F5F5F5;
    --card: #FFFFFF;
    --text: #212121;
    --text-2: #757575;
    --hint: #BDBDBD;
    --expense: #F44336;
    --income: #4CAF50;
    --divider: #E0E0E0;
    --header-h: 52px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    font-size: 15px;
}

#app {
    max-width: 640px;
    margin: 0 auto;
    min-height: 100vh;
}

button { font: inherit; border: none; cursor: pointer; }
input { font: inherit; }

/* 顶部栏 */
.header {
    position: sticky;
    top: 0;
    z-index: 10;
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 8px;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12);
}
.header .title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.header .side { width: 84px; display: flex; }
.header .side.right { justify-content: flex-end; }
.header .icon-btn {
    background: transparent;
    color: #fff;
    height: 40px;
    min-width: 40px;
    padding: 0 8px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
}
.header .icon-btn:active { background: rgba(255, 255, 255, .2); }
.header .back::before {
    content: "";
    width: 11px;
    height: 11px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(45deg);
    margin-left: 6px;
}

.page { padding: 12px 12px calc(96px + var(--safe-bottom)); }

/* 卡片 */
.card {
    background: var(--card);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
    margin-bottom: 10px;
}
.card.clickable:active { background: #FAFAFA; }

/* 汇总卡片 */
.summary {
    display: flex;
    padding: 16px 0;
}
.summary .cell {
    flex: 1;
    text-align: center;
}
.summary .cell + .cell { border-left: 1px solid var(--divider); }
.summary .label { font-size: 13px; color: var(--text-2); }
.summary .value { font-size: 20px; font-weight: 700; margin-top: 4px; }

.expense { color: var(--expense); }
.income { color: var(--income); }

/* 列表项 */
.list-item {
    display: flex;
    align-items: center;
    padding: 16px;
}
.list-item .main { flex: 1; min-width: 0; }
.list-item .arrow {
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--hint);
    border-top: 2px solid var(--hint);
    transform: rotate(45deg);
    margin-left: 12px;
}
.month-title { font-size: 17px; font-weight: 600; }
.sub-line { margin-top: 6px; font-size: 13px; color: var(--text-2); display: flex; gap: 16px; flex-wrap: wrap; }
.sub-line b { font-weight: 600; }

.day-badge {
    width: 48px;
    height: 48px;
    border-radius: 24px;
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-right: 14px;
    flex-shrink: 0;
}
.day-badge .d { font-size: 18px; font-weight: 700; line-height: 1; }
.day-badge .w { font-size: 10px; margin-top: 3px; opacity: .9; }

.count-badge {
    background: #EEEEEE;
    color: var(--text-2);
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 12px;
}

/* 记录卡片 */
.record { padding: 14px 16px; }
.record .row { display: flex; align-items: center; }
.record .cat { flex: 1; font-size: 16px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record .amt { font-size: 18px; font-weight: 700; margin-left: 8px; }
.type-tag {
    font-size: 12px;
    color: #fff;
    border-radius: 4px;
    padding: 2px 6px;
    margin-left: 8px;
    flex-shrink: 0;
}
.type-tag.expense { background: var(--expense); color: #fff; }
.type-tag.income { background: var(--income); color: #fff; }
.record .opr { margin-top: 6px; font-size: 12px; color: var(--text-2); }
.record .opr span { margin-left: 12px; }
.header .user-name {
    padding-left: 8px;
    font-size: 13px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* 空状态 */
.empty-view {
    text-align: center;
    color: var(--text-2);
    padding: 80px 0;
}
.empty-view .icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: #EEEEEE;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--hint);
}

/* 悬浮按钮 */
.fab {
    position: fixed;
    right: max(20px, calc(50vw - 300px));
    bottom: calc(24px + var(--safe-bottom));
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--accent);
    color: #fff;
    font-size: 30px;
    line-height: 56px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, .25);
    z-index: 20;
}
.fab:active { transform: scale(.95); }

/* 表单 */
.form { padding: 4px 16px; }
.field {
    display: flex;
    align-items: center;
    min-height: 54px;
    border-bottom: 1px solid var(--divider);
}
.field:last-child { border-bottom: none; }
.field label { width: 76px; color: var(--text-2); flex-shrink: 0; }
.field input[type=text], .field input[type=password], .field input[type=date] {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    height: 44px;
    font-size: 16px;
    color: var(--text);
    -webkit-appearance: none;
}
.field input[type=date] { cursor: pointer; caret-color: transparent; }
.date-box { flex: 1; min-width: 0; position: relative; height: 44px; display: flex; align-items: center; font-size: 16px; }
.date-text.empty { color: var(--hint); }
.date-box input[type=date] { position: absolute; left: 0; top: 0; width: 100%; height: 100%; opacity: 0; }
.field select {
    flex: 1;
    min-width: 0;
    height: 44px;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;
    color: var(--text);
    -webkit-appearance: none;
    appearance: none;
    padding-right: 20px;
    background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%);
    background-position: calc(100% - 10px) 50%, calc(100% - 5px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
}
.field select:invalid, .field select option[value=""] { color: var(--hint); }
.field input::placeholder { color: var(--hint); }
.field .err { color: var(--expense); font-size: 12px; margin-left: 8px; white-space: nowrap; }

.segment {
    display: flex;
    border: 1px solid var(--primary);
    border-radius: 6px;
    overflow: hidden;
}
.segment button {
    padding: 6px 22px;
    background: #fff;
    color: var(--primary);
    font-size: 14px;
}
.segment button.active { background: var(--primary); color: #fff; }
.segment button[data-type=expense].active { background: var(--expense); }
.segment.expense-mode { border-color: var(--expense); }
.segment.expense-mode button:not(.active) { color: var(--expense); }

.btn {
    display: block;
    width: 100%;
    height: 46px;
    border-radius: 23px;
    font-size: 16px;
    margin-top: 14px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.primary:disabled { background: var(--hint); }
.btn.danger { background: #fff; color: var(--expense); border: 1px solid var(--expense); }
.btn.plain { background: #fff; color: var(--text-2); border: 1px solid var(--divider); }
.btn[hidden] { display: none; }

/* 底部导航栏 */
.page.with-tab { padding-bottom: calc(150px + var(--safe-bottom)); }
.fab.with-tab { bottom: calc(80px + var(--safe-bottom)); }
.tab-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 100%;
    max-width: 640px;
    display: flex;
    background: #fff;
    border-top: 1px solid var(--divider);
    padding-bottom: var(--safe-bottom);
    z-index: 15;
}
.tab-bar .tab {
    flex: 1;
    height: 54px;
    background: transparent;
    color: var(--text-2);
    font-size: 15px;
}
.tab-bar .tab.active { color: var(--primary); font-weight: 600; }

/* 员工 */
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 21px;
    background: #E8F5E9;
    color: var(--primary);
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 14px;
    flex-shrink: 0;
}

/* 出勤日历 */
.cal { padding: 8px 8px 12px; }
.cal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 10px;
    font-size: 17px;
    font-weight: 600;
}
.cal-nav {
    width: 40px;
    height: 36px;
    border-radius: 18px;
    background: #F1F8E9;
    color: var(--primary);
    font-size: 24px;
    line-height: 32px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-week { text-align: center; font-size: 12px; color: var(--text-2); padding: 4px 0; }
/* 出勤页日历撑满页头和底部导航之间的区域 */
.page.cal-page {
    height: calc(100vh - var(--header-h) - 55px - var(--safe-bottom));
    height: calc(100dvh - var(--header-h) - 55px - var(--safe-bottom));
    padding: 8px 8px 0;
    display: flex;
    flex-direction: column;
}
.cal-page .cal { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-bottom: 8px; }
.cal-page .cal-grid { flex: 1; min-height: 0; grid-template-rows: auto repeat(var(--weeks), minmax(0, 1fr)); }
.cal-page .cal-legend { padding-bottom: 8px; }
.cal-cell {
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    border-radius: 8px;
    background: #FAFAFA;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 4px 2px;
    gap: 2px;
    cursor: pointer;
}
.cal-cell.blank { background: transparent; cursor: default; }
.cal-cell:not(.blank):active { background: #E8F5E9; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--primary); }
.cal-d { font-size: 14px; font-weight: 600; text-align: center; }

/* 日历中每个人的出勤标记：实心全天，空心半天，灰色休息 */
.cal-p {
    font-size: 10px;
    line-height: 14px;
    border-radius: 3px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    border: 1px solid transparent;
}
.cal-p.work { background: var(--income); color: #fff; }
.cal-p.work.half { background: #fff; color: var(--income); border-color: var(--income); }
.cal-p.rest { background: #E0E0E0; color: var(--text-2); }
.cal-more { font-size: 10px; color: var(--text-2); text-align: center; line-height: 12px; }
.cal-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    font-size: 12px;
    color: var(--text-2);
    padding: 0 4px 12px;
}
.cal-legend .cal-p { display: inline-block; padding: 0 4px; margin-right: 3px; font-style: normal; }

.day-empty { padding: 20px 16px; text-align: center; color: var(--hint); font-size: 14px; }

/* 出勤统计表 */
.stat-title { font-size: 14px; color: var(--text-2); padding: 8px 4px; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stat-table th, .stat-table td { padding: 10px 6px; text-align: right; border-bottom: 1px solid var(--divider); white-space: nowrap; }
.stat-table th:first-child, .stat-table td:first-child { text-align: left; padding-left: 16px; white-space: normal; }
.stat-table th:last-child, .stat-table td:last-child { padding-right: 16px; }
.stat-table th { font-weight: 500; color: var(--text-2); font-size: 13px; }
.stat-table tr:last-child td { border-bottom: none; }
.stat-table tr.total td { font-weight: 700; }
.stat-picker { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stat-picker .cal-nav { background: #fff; }
.stat-picker span { font-size: 17px; font-weight: 600; }

/* 出勤登记 */
.att-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px 10px;
    font-size: 13px;
    color: var(--text-2);
}
.att-bar span { flex: 1; }
.btn-mini {
    height: 30px;
    padding: 0 12px;
    border-radius: 15px;
    background: #fff;
    color: var(--primary);
    border: 1px solid var(--primary);
    font-size: 13px;
}
.att-row { padding: 12px 16px; border-bottom: 1px solid var(--divider); }
.att-row:last-child { border-bottom: none; }
.att-line { display: flex; align-items: center; }
.att-name { flex: 1; font-size: 16px; font-weight: 600; }
.att-seg { display: flex; border-radius: 6px; overflow: hidden; border: 1px solid var(--divider); }
.att-seg button { padding: 6px 16px; background: #fff; color: var(--text-2); font-size: 14px; }
.att-seg button + button { border-left: 1px solid var(--divider); }
.att-seg button.work.active { background: var(--income); color: #fff; }
.att-seg button.rest.active { background: #9E9E9E; color: #fff; }
.att-project {
    width: 100%;
    height: 38px;
    margin-top: 10px;
    border: 1px solid var(--divider);
    border-radius: 6px;
    padding: 0 10px;
    font-size: 15px;
    background: #fff;
    color: var(--text);
    outline: none;
}
.att-hint { font-size: 12px; color: var(--hint); text-align: center; }
.att-opts { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.att-opts .att-seg { flex: 0 0 120px; height: 38px; }
.att-opts .att-seg button { flex: 1; padding: 0; }
.att-opts .att-seg button.on { background: var(--primary); color: #fff; }
.att-opts .att-project { flex: 1; min-width: 0; margin-top: 0; }
.att-opts.wrap { flex-wrap: wrap; }
.att-opts.wrap .att-project { flex-basis: 100%; }
.att-remark {
    width: 100%;
    height: 36px;
    margin-top: 8px;
    border: 1px solid var(--divider);
    border-radius: 6px;
    padding: 0 10px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    outline: none;
}
.att-remark::placeholder { color: var(--hint); }
.att-wage { margin-left: 8px; font-size: 12px; font-weight: 400; color: var(--text-2); }

/* 记账明细 */
.btn.scan-btn { margin: 0 0 12px; color: var(--primary); border-color: var(--primary); }
#itemSum { margin-left: 6px; font-weight: 400; }
.item-row { padding: 10px 16px; border-bottom: 1px solid var(--divider); }
.item-row:last-child { border-bottom: none; }
.item-row input {
    width: 100%;
    min-width: 0;
    height: 34px;
    border: 1px solid var(--divider);
    border-radius: 6px;
    padding: 0 8px;
    font-size: 15px;
    background: #fff;
    outline: none;
}
.item-line { display: flex; gap: 8px; align-items: center; }
.item-del { flex: 0 0 34px; height: 34px; font-size: 22px; color: var(--hint); background: none; }
.item-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.item-nums label { font-size: 12px; color: var(--text-2); }
.item-nums input { margin-top: 2px; }
.item-add { display: block; margin: 10px auto 0; }

/* 项目成本 */
.proj-state { margin-left: 8px; font-size: 12px; font-weight: 400; vertical-align: middle; }
.proj-state.ended { background: #FFF3E0; color: #E65100; }
.proj-total { margin-top: 8px; font-size: 13px; color: var(--text-2); }
.proj-total b { font-size: 17px; color: var(--expense); }
.proj-cost { width: 100%; margin-top: 6px; border-collapse: collapse; font-size: 13px; }
.proj-cost th { font-weight: 400; color: var(--hint); text-align: right; padding: 2px 0; }
.proj-cost td { text-align: right; padding: 2px 0; }
.proj-cost th:first-child, .proj-cost td:first-child { text-align: left; color: var(--text-2); width: 40px; }

/* 无编辑权限时整块表单只读 */
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* 角色权限勾选 */
.perm-group { padding: 12px 16px; border-bottom: 1px solid var(--divider); }
.perm-group:last-child { border-bottom: none; }
.perm-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; }
.perm-title span { flex: 1; }
.perm-items { display: flex; flex-wrap: wrap; gap: 8px; }
.perm-chip input { display: none; }
.perm-chip span {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 16px;
    border: 1px solid var(--divider);
    font-size: 14px;
    color: var(--text-2);
    background: #fff;
    cursor: pointer;
}
.perm-chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.role-tag {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #E8F5E9;
    color: var(--primary-dark);
}

/* 提示、对话框、加载 */
.toast {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, .78);
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 80vw;
    text-align: center;
    z-index: 1000;
    pointer-events: none;
}
.mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dialog {
    width: 80vw;
    max-width: 320px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}
.dialog .d-title { font-size: 17px; font-weight: 600; text-align: center; padding: 20px 20px 8px; }
.dialog .d-msg { font-size: 14px; color: var(--text-2); padding: 0 20px 20px; line-height: 1.6; white-space: pre-line; text-align: center; }
.dialog .d-btns { display: flex; border-top: 1px solid var(--divider); }
.dialog .d-btns button { flex: 1; height: 48px; background: #fff; font-size: 16px; color: var(--text-2); }
.dialog .d-btns button + button { border-left: 1px solid var(--divider); }
.dialog .d-btns button.ok { color: var(--primary); font-weight: 600; }
.dialog .d-btns button.ok.danger { color: var(--expense); }
.loading-box {
    background: rgba(0, 0, 0, .78);
    color: #fff;
    border-radius: 10px;
    padding: 20px 24px;
    text-align: center;
    font-size: 14px;
}
.spinner {
    width: 32px;
    height: 32px;
    margin: 0 auto 10px;
    border: 3px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
