/* === Variables === */
:root {
    --primary: #E51E2F;
    --primary-dark: #c4192a;
    --primary-light: #ff4d5e;
    --primary-bg: rgba(229,30,47,.06);
    --primary-ring: rgba(229,30,47,.18);
    --text: #2d3436;
    --text-secondary: #636e72;
    --text-muted: #b2bec3;
    --bg: #f5f6fa;
    --white: #fff;
    --border: #dfe6e9;
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #d63031;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; line-height: 1.6; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--border); padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }

/* === Header === */
.header {
    background: var(--primary);
    color: var(--white);
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.header-logo { display: flex; align-items: center; }
.header-logo:hover { text-decoration: none; opacity: .9; }
.header-logo-img { height: 42px; width: auto; display: block; margin-top: 5px; }
.header-nav { display: flex; align-items: center; gap: 1rem; }
.header-nav a { color: rgba(255,255,255,.85); font-size: .9rem; }
.header-nav a:hover { color: var(--white); text-decoration: none; }
.header-user { color: rgba(255,255,255,.7); font-size: .85rem; }
.btn-header-logout {
    background: rgba(255,255,255,.15);
    border-color: rgba(255,255,255,.3);
    color: var(--white);
}
.btn-header-logout:hover { background: rgba(255,255,255,.25); }

/* === Main === */
.main { flex: 1; padding: 2rem 1rem; }
.container { max-width: 1200px; margin: 0 auto; }

/* === Footer === */
.footer { padding: 1.5rem 1rem; text-align: center; color: var(--text-muted); font-size: .85rem; }

/* === Cards === */
.card {
    background: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--text); }
.card-header-flex { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-header-flex h2 { margin-bottom: 0; }

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.page-header h1 { font-size: 1.5rem; }

/* === Dashboard Summary === */
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.summary-card {
    background: var(--white);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    border-top: 3px solid var(--primary);
}
.summary-label { font-size: .85rem; color: var(--text-secondary); margin-bottom: .25rem; }
.summary-value { font-size: 1.5rem; font-weight: 700; color: var(--text); }

/* === Tables === */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: .65rem .75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}
.table th { font-size: .85rem; color: var(--text-secondary); font-weight: 600; background: #fafafa; }
.table tbody tr:hover { background: var(--primary-bg); }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.row-inactive { opacity: .5; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .5rem 1rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    line-height: 1;
    gap: .4rem;
}
.btn:hover { text-decoration: none; filter: brightness(.92); }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-warning { background: var(--warning); color: var(--text); }
.btn-dark { background: var(--text); color: var(--white); }
.btn-outline { background: transparent; border-color: var(--text-muted); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.4;
}
.badge-secondary { background: var(--border); color: var(--text-secondary); }
.badge-info { background: #74b9ff; color: var(--white); }
.badge-warning { background: #ffeaa7; color: #856404; }
.badge-danger { background: #fcd4d4; color: var(--primary); }
.badge-success { background: #d4f5e9; color: #00695c; }
.badge-dark { background: var(--text-secondary); color: var(--white); }
.badge-user-edited { background: #e0f0ff; color: #1565c0; border: 1px solid rgba(21,101,192,.2); }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: var(--text); }
.form-control {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .95rem;
    transition: border-color .15s, box-shadow .15s;
    background: var(--white);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.form-control:disabled { background: var(--bg); color: var(--text-secondary); }
.form-control-sm { padding: .35rem .5rem; font-size: .85rem; }
.required { color: var(--primary); }
.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-inline-add { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline-add .form-group { margin-bottom: 0; min-width: 180px; flex: 1; }

/* === Alerts === */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9rem; }
.alert-danger { background: #ffeef0; color: var(--primary); border: 1px solid rgba(229,30,47,.25); }
.alert-success { background: #eafff6; color: var(--success); border: 1px solid rgba(0,184,148,.3); }
.alert-warning-resolution {
    background: #fff8e1;
    color: #7c6800;
    border: 1px solid rgba(253,203,110,.6);
    padding: .75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: .9rem;
    line-height: 1.6;
}
.alert-warning-resolution strong { color: #e67e22; }
.alert-warning-resolution small { color: var(--text-secondary); }

/* === Login === */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
}
.login-card {
    background: var(--white);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.08);
    width: 100%;
    max-width: 420px;
}
.login-logo { text-align: center; margin-bottom: .5rem; }
.login-logo-img { height: 48px; width: auto; }
.login-title { font-size: 1.4rem; text-align: center; margin-bottom: .25rem; }
.login-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 1.5rem; }

/* === Empty State === */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-secondary); }
.empty-state .btn { margin-top: 1rem; }

/* === Month Selector === */
.month-selector { display: flex; flex-wrap: wrap; gap: .5rem; }

/* === Filter Bar === */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filter-bar > span { font-size: .85rem; color: var(--text-secondary); font-weight: 600; }

/* === Expense Detail === */
.expense-detail-grid { display: grid; grid-template-columns: 1fr 1.3fr; gap: 1.5rem; }
.expense-image-col { position: sticky; top: 72px; align-self: start; }
.receipt-image-wrapper { background: var(--bg); border-radius: 6px; overflow: hidden; text-align: center; line-height: 0; padding: 10px 0; }
.receipt-image {
    max-width: 100%;
    height: auto;
    cursor: zoom-in;
    border-radius: 4px;
}
.receipt-image.zoomed { cursor: zoom-out; max-width: none; width: auto; }

/* === List Thumbnail === */
.td-thumbnail { width: 48px; padding: .35rem .5rem !important; }
.list-thumbnail {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg);
    vertical-align: middle;
}

/* === Items === */
.item-row {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: .5rem;
}
.item-row input:first-child { flex: 2; }
.item-row input:nth-child(2) { flex: 1; }

/* === Confidence === */
.confidence-bar {
    height: 24px;
    background: var(--border);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger), var(--warning), var(--success));
    border-radius: 4px;
    transition: width .3s;
}
.confidence-bar span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: .8rem;
    font-weight: 600;
    color: var(--text);
}

/* === Meta List === */
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; font-size: .85rem; }
.meta-list dt { color: var(--text-secondary); font-weight: 600; }
.meta-list dd { color: var(--text); }

/* === Actions Cell === */
.actions-cell { display: flex; gap: .4rem; }

/* === Dialog === */
.dialog {
    border: none;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,.15);
    padding: 2rem;
    max-width: 460px;
    width: 90%;
}
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog h2 { margin-bottom: 1.25rem; }

/* === Room ID format bubble (above input) === */
.room-id-format-bubble {
    position: fixed;
    z-index: 9998;
    padding: .5rem .75rem;
    background: var(--primary);
    color: var(--white);
    font-size: .8rem;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    text-align: center;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .2s, transform .2s;
    pointer-events: none;
}
.room-id-format-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: var(--primary);
}
.room-id-format-bubble-visible {
    opacity: 1;
    transform: translateY(0);
}

/* === Notification Toast === */
.notification {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: .75rem 1.25rem;
    border-radius: 8px;
    font-size: .9rem;
    font-weight: 500;
    z-index: 9999;
    opacity: 0;
    transform: translateY(10px);
    transition: all .3s;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.notification.show { opacity: 1; transform: translateY(0); }
.notification-success { background: var(--success); color: var(--white); }
.notification-error { background: var(--primary); color: var(--white); }

/* === Responsive === */
@media (max-width: 768px) {
    .expense-detail-grid { grid-template-columns: 1fr; }
    .expense-image-col { position: static; }
    .form-row { grid-template-columns: 1fr; }
    .form-inline-add { flex-direction: column; align-items: stretch; }
    .dashboard-summary { grid-template-columns: 1fr 1fr; }
    .header-inner { flex-wrap: wrap; gap: .5rem; height: auto; padding: .5rem 0; }
    .header-nav { gap: .5rem; flex-wrap: wrap; }
}
