/* ===== Cat Finance - ธีมแมวสุดคิวต์ ===== */

@import url('https://fonts.googleapis.com/css2?family=Mali:wght@300;400;600&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Mali', cursive;
    background-color: #f9f3e8;
    background-image: url('data:image/svg+xml;utf8,<svg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"><path d="M20 20 Q25 15 30 20 Q35 25 30 30 Q25 35 20 30 Q15 25 20 20" fill="%23d9b48c" opacity="0.1"/><path d="M40 40 Q45 35 50 40 Q55 45 50 50 Q45 55 40 50 Q35 45 40 40" fill="%23d9b48c" opacity="0.1"/></svg>');
    color: #5e3a2c;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 20px;
    flex: 1;
}

/* ===== Header ===== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff2df;
    padding: 15px 25px;
    border-radius: 60px;
    margin-bottom: 30px;
    border: 3px solid #f9cfb5;
    box-shadow: 0 6px 0 #d9a78b;
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.paw-icon {
    width: 50px;
    height: 50px;
    animation: earWiggle 2s infinite;
    transform-origin: top center;
    filter: drop-shadow(2px 4px 4px rgba(180, 95, 95, 0.3));
}

@keyframes earWiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-8deg); }
    75% { transform: rotate(8deg); }
}

.logo h1 {
    font-size: 2rem;
    color: #b45f5f;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    text-shadow: 2px 2px 0 #ffe4cc;
}

.subtitle {
    font-size: 1rem;
    color: #b48c5c;
    font-weight: 300;
    margin-left: 10px;
}

.cat-logo-decoration {
    font-size: 1.8rem;
    margin-left: 5px;
    animation: bounce 2s infinite;
    display: inline-block;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* ===== ปุ่มและสถานะผู้ใช้ ===== */
.user-status {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.badge {
    padding: 6px 18px;
    border-radius: 40px;
    font-size: 1rem;
    background: white;
    border: 2px solid #f9cfb5;
}

.badge.admin {
    background: #f1c6b3;
    color: #7b3f00;
}

.badge.guest {
    background: #e6e6e6;
    color: #5e3a2c;
}

.btn {
    padding: 8px 20px;
    border-radius: 40px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 2px solid #f9cfb5;
    background: white;
    color: #b45f5f;
    box-shadow: 0 4px 0 #d9a78b;
    cursor: pointer;
    font-family: 'Mali', cursive;
    font-size: 1rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #d9a78b;
}

.btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #d9a78b;
}

.btn-login { 
    background: #b45f5f; 
    color: white; 
    border-color: #9e4e4e; 
}

.btn-logout { 
    background: #d9d9d9; 
    color: #5e3a2c; 
    border-color: #b0b0b0; 
}

.btn-add { 
    background: #a8d5ba; 
    color: #2d5a3a; 
    border-color: #7fb77e; 
    margin-bottom: 20px;
    font-size: 1.1rem;
    padding: 12px 25px;
}

/* ===== การ์ดสรุป ===== */
.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 25px;
    margin-bottom: 35px;
}

.card {
    background: white;
    padding: 20px;
    border-radius: 50px;
    text-align: center;
    border: 3px solid #f9cfb5;
    box-shadow: 0 8px 0 #d9a78b;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 0 #d9a78b;
}

.card::after {
    content: "🐾";
    position: absolute;
    bottom: -10px;
    right: -10px;
    font-size: 4rem;
    opacity: 0.2;
    transform: rotate(10deg);
    transition: 0.2s;
}

.card:hover::after {
    opacity: 0.4;
    transform: rotate(0deg) scale(1.2);
}

.card i {
    font-size: 2.8rem;
    margin-bottom: 10px;
}

.card.income i { color: #7fb77e; }
.card.expense i { color: #f19a9a; }
.card.balance i { color: #b48c5c; }

.card h3 {
    font-size: 1.3rem;
    font-weight: 400;
    margin-bottom: 10px;
}

.amount {
    font-size: 2.2rem;
    font-weight: 600;
}

.positive { color: #7fb77e; }
.negative { color: #f19a9a; }

/* ===== กราฟวงกลม ===== */
.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 35px;
}

@media (max-width: 768px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    background: white;
    border-radius: 50px;
    padding: 25px;
    border: 3px solid #f9cfb5;
    box-shadow: 0 8px 0 #d9a78b;
    position: relative;
}

.chart-card h3 {
    color: #b45f5f;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
}

.chart-wrapper {
    position: relative;
    height: 250px;
    width: 100%;
    margin-bottom: 15px;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
    padding: 5px 12px;
    background: #fffaf2;
    border-radius: 40px;
    border: 1px solid #f9cfb5;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-value {
    font-weight: 600;
    margin-left: 5px;
    color: #b45f5f;
}

.no-data-chart {
    text-align: center;
    padding: 40px;
    color: #d9a78b;
    font-size: 1.1rem;
}

/* ===== หมวดหมู่ ===== */
.categories-section {
    background: white;
    border-radius: 50px;
    padding: 30px;
    border: 3px solid #f9cfb5;
    box-shadow: 0 8px 0 #d9a78b;
    margin-bottom: 30px;
}

.categories-section h2 {
    color: #b45f5f;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.8rem;
}

.cat-emoji {
    font-size: 2rem;
    animation: bounce 2s infinite;
}

.category-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.category-card {
    background: #fffaf2;
    border-radius: 30px;
    padding: 20px;
    border: 2px solid #f9cfb5;
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 0 #d9a78b;
}

.category-card::before {
    content: "🐈";
    position: absolute;
    bottom: -5px;
    right: -5px;
    font-size: 3rem;
    opacity: 0.1;
    transform: rotate(5deg);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.category-name {
    font-size: 1.3rem;
    font-weight: 600;
    color: #b45f5f;
    display: flex;
    align-items: center;
    gap: 5px;
}

.category-icon {
    font-size: 1.8rem;
}

.category-percent {
    background: #ffe4cc;
    padding: 5px 15px;
    border-radius: 40px;
    color: #b45f5f;
    font-weight: 600;
}

.category-amount {
    font-size: 1.8rem;
    font-weight: 600;
    margin: 10px 0;
}

.category-bar {
    width: 100%;
    height: 12px;
    background: #f0d9cc;
    border-radius: 20px;
    margin: 15px 0;
    overflow: hidden;
}

.category-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #f19a9a, #b45f5f);
    border-radius: 20px;
    transition: width 0.5s;
}

.income-cats .category-bar-fill {
    background: linear-gradient(90deg, #a8d5ba, #7fb77e);
}

.total-card {
    background: #fff2df;
    border: 3px solid #b45f5f;
}

.total-card .category-amount {
    font-size: 2rem;
}

/* ===== ตารางรายการ ===== */
.transaction-list {
    background: white;
    border-radius: 50px;
    padding: 30px;
    border: 3px solid #f9cfb5;
    box-shadow: 0 8px 0 #d9a78b;
    margin-bottom: 30px;
    overflow-x: auto;
}

.transaction-list h2 {
    color: #b45f5f;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.8rem;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
    min-width: 800px;
}

th {
    text-align: left;
    padding: 12px 15px;
    background: #fff2df;
    color: #b45f5f;
    font-weight: 500;
    font-size: 1.1rem;
    border-radius: 30px 30px 0 0;
    white-space: nowrap;
}

td {
    padding: 15px;
    background: #fffaf2;
    border-radius: 30px;
    transition: 0.2s;
    white-space: nowrap;
}

tr:hover td {
    background: #ffe9d6;
    transform: scale(1.01);
    box-shadow: 0 4px 8px rgba(180, 95, 95, 0.2);
}

.income-text { color: #7fb77e; font-weight: 600; }
.expense-text { color: #f19a9a; font-weight: 600; }

.badge.income-badge { 
    background: #e2f0da; 
    color: #2d5a3a; 
    border-radius: 40px; 
    padding: 5px 15px; 
    display: inline-block;
}

.badge.expense-badge { 
    background: #ffe0e0; 
    color: #b35f5f; 
    border-radius: 40px; 
    padding: 5px 15px; 
    display: inline-block;
}

.actions {
    display: flex;
    gap: 15px;
    white-space: nowrap;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: #b48c5c;
    transition: 0.2s;
    cursor: pointer;
    padding: 5px;
}
.btn-icon:hover { transform: scale(1.2); }
.btn-icon.edit:hover { color: #7fb77e; }
.btn-icon.delete:hover { color: #f19a9a; }

.no-data {
    text-align: center;
    padding: 50px;
    color: #d9a78b;
    font-size: 1.3rem;
    background: #fffaf2;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #fefefe;
    margin: 3% auto;
    padding: 25px;
    border: 3px solid #f9cfb5;
    border-radius: 50px;
    width: 90%;
    max-width: 550px;
    position: relative;
    animation: modalPop 0.3s;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.close {
    color: #b48c5c;
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
}

.close:hover {
    color: #b45f5f;
}

/* ===== ฟอร์ม ===== */
.cat-form {
    background: #fffaf2;
    padding: 30px 25px;
    border-radius: 60px;
    background-image: radial-gradient(circle at 10px 10px, #f9cfb5 2px, transparent 2px);
    background-size: 30px 30px;
}

.cat-form h2 {
    color: #b45f5f;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.8rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #b48c5c;
    font-weight: 500;
    font-size: 1.1rem;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 12px 18px;
    border: 3px solid #f9cfb5;
    border-radius: 40px;
    font-family: 'Mali', cursive;
    font-size: 1rem;
    outline: none;
    transition: 0.2s;
    background: white;
}

.form-group input:focus, .form-group select:focus {
    border-color: #b45f5f;
    box-shadow: 0 0 0 4px #ffe4cc;
}

.form-row {
    display: flex;
    gap: 15px;
}

.form-row .form-group {
    flex: 1;
}

@media (max-width: 500px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

.btn-save {
    background: #a8d5ba;
    color: #2d5a3a;
    flex: 1;
    text-align: center;
    font-size: 1.2rem;
    border-color: #7fb77e;
    padding: 14px;
}

.btn-cancel {
    background: #f0d9cc;
    color: #b45f5f;
    flex: 1;
    text-align: center;
    font-size: 1.2rem;
    border-color: #d9a78b;
    padding: 14px;
}

/* ===== หน้า login modal ===== */
.login-box {
    text-align: center;
    padding: 35px 25px;
}

.cat-login {
    width: 100px;
    margin-bottom: 15px;
    animation: bounce 2s infinite;
}

.login-box h2 {
    color: #b45f5f;
    margin-bottom: 25px;
    font-size: 1.8rem;
}

.error-msg {
    background: #ffe0e0;
    color: #b35f5f;
    padding: 12px;
    border-radius: 40px;
    margin-bottom: 20px;
    border: 2px solid #f19a9a;
}

.remember-me {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
    justify-content: center;
}

.remember-me input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #b45f5f;
}

.remember-me label {
    color: #b48c5c;
    font-size: 1rem;
}

.btn-login-submit {
    width: 100%;
    padding: 16px;
    background: #b45f5f;
    color: white;
    border: none;
    border-radius: 60px;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-family: 'Mali', cursive;
    border: 3px solid #9e4e4e;
    box-shadow: 0 6px 0 #6b2e2e;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-login-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #6b2e2e;
}

/* ===== ระบบจัดการหมวดหมู่ ===== */
.admin-category-btn {
    background: #f1c6b3;
    color: #7b3f00;
    border: none;
    border-radius: 40px;
    padding: 8px 15px;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: 'Mali', cursive;
    border: 2px solid #d9a78b;
}

.admin-category-btn:hover {
    background: #e6b59e;
    transform: translateY(-2px);
}

.category-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: #f0d9cc;
    border-radius: 40px;
    font-family: 'Mali', cursive;
    font-size: 1.1rem;
    cursor: pointer;
    transition: 0.2s;
    color: #5e3a2c;
}

.tab-btn.active {
    background: #b45f5f;
    color: white;
    box-shadow: 0 4px 0 #6b2e2e;
}

.category-list {
    display: none;
    margin-bottom: 20px;
    max-height: 400px;
    overflow-y: auto;
    padding: 5px;
}

.category-list.active {
    display: block;
}

.category-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: #fffaf2;
    border-radius: 40px;
    margin-bottom: 10px;
    border-left: 5px solid;
    transition: 0.2s;
}

.category-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.cat-icon {
    font-size: 1.8rem;
    margin-right: 15px;
    width: 40px;
    text-align: center;
}

.cat-name {
    flex: 1;
    font-size: 1.2rem;
    font-weight: 500;
}

.cat-actions {
    display: flex;
    gap: 10px;
}

.cat-edit, .cat-delete {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.cat-edit {
    color: #7fb77e;
}
.cat-edit:hover {
    background: #e2f0da;
    transform: scale(1.1);
}

.cat-delete {
    color: #f19a9a;
}
.cat-delete:hover {
    background: #ffe0e0;
    transform: scale(1.1);
}

.btn-add-category {
    width: 100%;
    padding: 15px;
    background: #a8d5ba;
    color: #2d5a3a;
    border: none;
    border-radius: 40px;
    font-size: 1.1rem;
    cursor: pointer;
    font-family: 'Mali', cursive;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.btn-add-category:hover {
    background: #7fb77e;
    transform: translateY(-2px);
}

/* ===== อนิเมชันแมวเดินและแอบมอง ===== */
.walking-cat {
    position: fixed;
    bottom: 20px;
    left: 0;
    width: 100%;
    pointer-events: none;
    z-index: 1000;
}
.cat-walk {
    font-size: 3.5rem;
    position: absolute;
    bottom: 0;
    left: -100px;
    animation: walk 20s linear infinite;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.2));
}
@keyframes walk {
    0% { left: -100px; transform: scaleX(1); }
    49% { transform: scaleX(1); }
    50% { left: calc(100% + 100px); transform: scaleX(-1); }
    100% { left: -100px; transform: scaleX(-1); }
}

.peek-cat {
    position: fixed;
    bottom: 30px;
    right: 30px;
    font-size: 4rem;
    animation: peek 6s infinite;
    filter: drop-shadow(0 8px 10px rgba(0,0,0,0.2));
    z-index: 999;
}
@keyframes peek {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    30% { transform: translateY(-15px) rotate(5deg); }
    70% { transform: translateY(-5px) rotate(-3deg); }
}

/* ===== footer ===== */
footer {
    text-align: center;
    padding: 25px;
    color: #b48c5c;
    font-size: 1rem;
    margin-top: auto;
    position: relative;
}
footer::before {
    font-size: 2rem;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: -15px;
    opacity: 0.5;
}

.credit {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-top: 5px;
}

/* ===== responsive ===== */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        text-align: center;
    }
    
    .logo {
        justify-content: center;
    }
    
    .cat-logo-decoration {
        display: none;
    }
    
    .user-status {
        justify-content: center;
    }
    
    .summary {
        grid-template-columns: 1fr;
    }
    
    .category-summary {
        grid-template-columns: 1fr;
    }
    
    /* responsive table */
    table, thead, tbody, th, td, tr {
        display: block;
    }
    
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    tr {
        margin-bottom: 15px;
        border: 2px solid #f9cfb5;
        border-radius: 30px;
        padding: 10px;
        background: #fffaf2;
    }
    
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 10px;
        background: none;
        border: none;
        white-space: normal;
        word-break: break-word;
    }
    
    td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #b45f5f;
        margin-right: 10px;
        min-width: 100px;
    }
    
    .actions {
        justify-content: center;
    }
}
/* เพิ่มสไตล์สำหรับคอลัมน์คงเหลือ */
td[data-label="คงเหลือ"] {
    font-weight: 600;
}

.positive {
    color: #7fb77e;
}

.negative {
    color: #f19a9a;
}

/* ปรับ responsive */
@media (max-width: 768px) {
    td[data-label="คงเหลือ"]:before {
        content: "💰 คงเหลือ: ";
        font-weight: 600;
        color: #b45f5f;
    }
}