/* ============================================================
   FatCat Accounting System - Styles
   簡約現代風格，響應式 (手機優先)
   ============================================================ */

:root {
    --bg:           #f6f7fb;
    --surface:      #ffffff;
    --surface-2:    #f1f3f8;
    --border:       #e3e6ef;
    --text:         #0f172a;
    --text-muted:   #64748b;
    --primary:      #4f46e5;
    --primary-dark: #4338ca;
    --income:       #10b981;
    --income-bg:    #d1fae5;
    --expense:      #ef4444;
    --expense-bg:   #fee2e2;
    --danger:       #dc2626;
    --warning:      #f59e0b;
    --shadow-sm:    0 1px 2px rgba(15, 23, 42, .05);
    --shadow:       0 4px 12px rgba(15, 23, 42, .08);
    --shadow-lg:    0 12px 32px rgba(15, 23, 42, .12);
    --radius:       14px;
    --radius-sm:    8px;
    --gap:          16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
                 "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ----- Header ----- */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 17px;
}
.logo { font-size: 22px; }
.nav { display: flex; gap: 4px; }
.nav-item {
    text-decoration: none;
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all .2s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
    background: var(--primary);
    color: #fff;
}
.nav-user {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.nav-logout {
    color: var(--danger) !important;
}
.nav-logout:hover {
    background: var(--expense-bg) !important;
    color: var(--danger) !important;
}
/* 使用者選單下拉 */
.nav-user-menu { position: relative; display: none; }
.nav-user-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 10px;
    font-size: 16px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background .2s;
}
.nav-user-btn:hover { background: var(--surface-2); }
.nav-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    min-width: 200px;
    z-index: 200;
    margin-top: 6px;
    overflow: hidden;
}
.nav-dropdown.show { display: block; }
.nav-dropdown-user {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.nav-dropdown-user strong { color: var(--text); font-size: 14px; display: block; margin-bottom: 2px; }
.nav-dropdown-item {
    display: block;
    padding: 11px 14px;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    transition: background .15s;
}
.nav-dropdown-item:hover { background: var(--surface-2); }
.nav-dropdown-item.nav-logout { color: var(--danger) !important; }
@media (max-width: 600px) {
    .nav-item-desktop, .nav-user { display: none !important; }
    .nav-user-menu { display: block; }
}
@media (min-width: 601px) {
    .nav-user-menu { display: none; }
}

/* ----- Layout ----- */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    padding-bottom: 80px;
}

/* ----- Card ----- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.card-title {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.count {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ----- Room grid 5 (multi-timer) ----- */
.room-grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 8px;
}
.room-timer {
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 6px;
    text-align: center;
    transition: all .2s;
    position: relative;
    overflow: hidden;
}
.room-timer.r1 { --room-color: #2563eb; --room-bg: #dbeafe; }
.room-timer.r2 { --room-color: #db2777; --room-bg: #fce7f3; }
.room-timer.r3 { --room-color: #059669; --room-bg: #d1fae5; }
.room-timer.r4 { --room-color: #d97706; --room-bg: #fef3c7; }
.room-timer.r5 { --room-color: #7c3aed; --room-bg: #ede9fe; }

.room-timer.running {
    background: var(--room-bg);
    border-color: var(--room-color);
}
.room-timer.overdue {
    background: #fee2e2;
    border-color: var(--danger);
    animation: roomPulse 1.5s infinite;
}
@keyframes roomPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .35); }
    50%      { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}
.room-timer.warning {
    background: #fef3c7;
    border-color: var(--warning);
}

.room-num {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: .5px;
    margin-bottom: 4px;
}
.room-timer.running .room-num { color: var(--room-color); }

.room-time {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: 'SF Mono','Consolas',monospace;
    color: var(--text);
    line-height: 1.2;
    margin: 4px 0;
}
.room-timer.overdue .room-time { color: var(--danger); }
.room-timer.warning .room-time { color: var(--warning); }

.room-status {
    font-size: 10px;
    color: var(--text-muted);
    height: 14px;
    margin-bottom: 6px;
}
.room-timer.running .room-status { color: var(--room-color); }

.room-btn {
    width: 100%;
    padding: 6px 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    transition: all .15s;
}
.room-btn:hover { border-color: var(--room-color); color: var(--room-color); }
.room-btn.primary {
    background: var(--room-color);
    border-color: var(--room-color);
    color: #fff;
}
.room-btn.primary:hover {
    filter: brightness(.92);
    color: #fff;
}
.room-btn.stop {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}
.room-btn.stop:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

@media (max-width: 600px) {
    .room-grid-5 { gap: 6px; }
    .room-timer   { padding: 10px 4px; }
    .room-time    { font-size: 15px; }
    .room-num     { font-size: 11px; }
    .room-btn     { font-size: 11px; padding: 5px 0; }
    .room-status  { display: none; }
}
@media (max-width: 380px) {
    .room-time { font-size: 13px; }
}

/* ----- Timer ----- */
.timer-card { text-align: center; }
.timer-display {
    font-size: 56px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    color: var(--text);
    margin: 8px 0 4px;
    font-family: 'SF Mono', 'Consolas', monospace;
}
.timer-display.running { color: var(--primary); }
.timer-display.warning { color: var(--warning); }
.timer-display.overdue { color: var(--expense); animation: pulse 1.2s infinite; }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .55; }
}
.timer-meta {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 14px;
}
.timer-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.alarm-note {
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ----- Summary ----- */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.summary-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    background: var(--surface-2);
}
.summary-item .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.summary-item .value { font-size: 18px; font-weight: 700; }
.summary-item.income .value  { color: var(--income); }
.summary-item.expense .value { color: var(--expense); }
.summary-item.balance .value { color: var(--primary); }

/* ----- Tabs ----- */
.tabs {
    display: flex;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 16px;
}
.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all .2s;
}
.tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}
.tab[data-type="income"].active  { color: var(--income); }
.tab[data-type="expense"].active { color: var(--expense); }

/* ----- Form ----- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.form-row label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}
input, select, textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
    box-sizing: border-box;
}
input[type="date"], input[type="time"], input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}
.form-row, .filter-row { min-width: 0; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

/* ----- Category grid ----- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}
.cat-chip {
    padding: 10px 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    transition: all .15s;
    user-select: none;
    font-size: 13px;
}
.cat-chip:hover { border-color: var(--primary); }
.cat-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.cat-chip .icon { font-size: 20px; display: block; margin-bottom: 2px; }

/* ----- Buttons ----- */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #b91c1c; }
.btn-ghost   { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover:not(:disabled)   { background: var(--border); }
.btn-block   { width: 100%; padding: 12px; }

/* ----- Filter ----- */
.filter-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}
.filter-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}
.quick-filters {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 16px;
}
.quick-filters .quick-btn {
    width: 100%;
    justify-content: center;
    font-size: 14px;
    padding: 10px 8px;
}

/* ----- Records ----- */
.record-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 60vh;
    overflow-y: auto;
}
.record-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border-left: 3px solid transparent;
}
.record-item.income  { border-left-color: var(--income); }
.record-item.expense { border-left-color: var(--expense); }
.record-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.record-body { flex: 1; min-width: 0; }
.record-title { font-weight: 600; font-size: 14px; }
.record-meta  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.record-amount { font-weight: 700; font-size: 16px; flex-shrink: 0; }
.record-amount.income  { color: var(--income); }
.record-amount.expense { color: var(--expense); }
.room-tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-muted);
    margin-right: 4px;
    vertical-align: middle;
}
.room-tag.r1 { background: #dbeafe; color: #1d4ed8; }
.room-tag.r2 { background: #fce7f3; color: #be185d; }
.room-tag.r3 { background: #d1fae5; color: #047857; }
.room-tag.r4 { background: #fef3c7; color: #b45309; }
.room-tag.r5 { background: #ede9fe; color: #6d28d9; }
.record-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ----- Records (table layout) ----- */
.record-list { max-height: none; }
.table-wrap {
    overflow-x: auto;
    margin: -4px;
    padding: 4px;
}
.record-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.record-table thead th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--surface);
    position: sticky;
    top: 0;
}
.record-table th.th-amount { text-align: right; }
.record-row {
    transition: background .15s;
}
.record-row:hover { background: var(--surface-2); }
.record-row td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.cell-date { white-space: nowrap; }
.date-main { font-weight: 600; font-variant-numeric: tabular-nums; }
.date-sub  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.cell-type { white-space: nowrap; }
.type-pill {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}
.type-pill.income  { background: var(--income-bg);  color: var(--income); }
.type-pill.expense { background: var(--expense-bg); color: var(--expense); }
.cell-note { min-width: 160px; }
.note-main { font-weight: 500; }
.cat-name  { color: var(--text); }
.note-sub  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.note-sub .muted { color: var(--text-muted); font-style: italic; }
.cell-room { white-space: nowrap; }
.cell-user { white-space: nowrap; font-size: 13px; color: var(--text-muted); }
.cell-amount {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.cell-amount.income  { color: var(--income); }
.cell-amount.expense { color: var(--expense); }
.cell-actions { white-space: nowrap; text-align: right; }

@media (max-width: 600px) {
    .record-table { font-size: 13px; }
    .record-table thead { display: none; }
    .record-row {
        display: flex !important;
        flex-wrap: wrap;
        align-items: flex-start;
        background: var(--surface-2);
        border-radius: var(--radius-sm);
        padding: 14px 12px;
        margin-bottom: 10px;
        border-left: 4px solid transparent;
    }
    .record-row.income  { border-left-color: var(--income); }
    .record-row.expense { border-left-color: var(--expense); }
    .record-row td {
        display: block;
        padding: 0;
        border-bottom: none;
        min-width: 0;
    }
    .record-row td::before { display: none; }
    /* 隱藏類型標籤，用左側顏色條表示 */
    .cell-type { display: none !important; }
    /* 第一行：分類備註(左) + 金額(右) */
    .cell-note {
        width: 65%;
        order: 1;
        padding-right: 10px;
    }
    .note-main {
        font-size: 15px;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    .note-sub {
        font-size: 12px;
        color: var(--text-muted);
        margin-top: 3px;
    }
    .cell-amount {
        width: 35%;
        order: 2;
        text-align: right;
        font-size: 17px;
        font-weight: 700;
        padding-top: 1px;
    }
    /* 第二行：日期 + 操作者 + 操作按鈕 */
    .cell-date {
        width: auto;
        order: 3;
        margin-top: 10px;
    }
    .date-main { font-size: 12px; color: var(--text-muted); font-weight: 400; }
    .date-sub { display: none; }
    .cell-user {
        width: auto;
        order: 4;
        margin-top: 10px;
        margin-left: 8px;
        font-size: 12px;
        color: var(--text-muted);
    }
    .cell-user::before { content: '· '; display: inline; }
    .cell-actions {
        width: auto;
        order: 5;
        margin-top: 6px;
        margin-left: auto;
        display: flex;
        gap: 4px;
    }
    .cell-actions .icon-btn { padding: 2px 6px; font-size: 14px; }
}

/* ----- Modal ----- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
    backdrop-filter: blur(4px);
}
.modal.show { display: flex; }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: pop .25s ease;
}
@keyframes pop {
    from { transform: scale(.85); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
.modal-icon {
    font-size: 56px;
    margin-bottom: 8px;
    animation: shake .5s ease-in-out infinite;
}
@keyframes shake {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-8deg); }
    75% { transform: rotate(8deg); }
}
.modal h3 { margin: 8px 0; }
.modal p  { color: var(--text-muted); margin: 8px 0 18px; }
.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}
.modal-actions .btn { flex: 1; }

/* ----- Toast ----- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all .3s;
    z-index: 200;
    pointer-events: none;
    max-width: 80vw;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.error   { background: var(--danger); }
.toast.success { background: var(--income); }

/* ----- Mobile tweaks ----- */
@media (max-width: 600px) {
    body { font-size: 14px; }
    .container { padding: 14px; }
    .card { padding: 16px; }
    .timer-display { font-size: 44px; }
    .summary-grid .value { font-size: 16px; }
    .filter-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .form-row.two-col { grid-template-columns: 1fr; gap: 12px; }
    .nav {
        gap: 4px;
        flex: 1;
        margin-left: 8px;
        align-items: center;
    }
    .nav-item { padding: 8px 14px; font-size: 14px; white-space: nowrap; flex-shrink: 0; }
    .nav-user { display: none; }
    .nav-user-menu { margin-left: auto; }
    .app-header { padding: 10px 12px; }
    .title { display: none; }
    .logo { font-size: 24px; }
    /* 確保所有輸入框不超出容器 */
    .card input, .card select, .card textarea {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }
    .form-group, .filter-row > div { min-width: 0; }
}

@media (min-width: 900px) {
    .container { max-width: 960px; }
    .timer-display { font-size: 64px; }
}