:root {
    --bg: #eef1f8;
    --bg-accent: #e4e9fb;
    --surface: #ffffff;
    --border: #e5e7f0;
    --text: #1a1d29;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef0ff;
    --accent: #7c3aed;
    --danger: #e11d48;
    --danger-light: #fef1f4;
    --warning: #d97706;
    --warning-light: #fef6e9;
    --success: #059669;
    --success-light: #ecfaf4;
    --info: #2563eb;
    --info-light: #eaf1ff;
    --teal: #0d9488;
    --teal-light: #e8f9f6;
    --sidebar-width: 232px;
    --bottom-nav-height: 62px;
    --shadow-sm: 0 1px 2px rgba(23, 24, 63, 0.05);
    --shadow-md: 0 2px 8px rgba(23, 24, 63, 0.06), 0 1px 2px rgba(23, 24, 63, 0.05);
    --shadow-lg: 0 12px 28px rgba(30, 24, 90, 0.12);
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
    background:
        radial-gradient(1100px 480px at 100% -10%, var(--bg-accent), transparent),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar (desktop) --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
    padding: 4px 10px 24px;
}

.brand::before {
    content: "SH";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 2px;
    transition: background-color .15s ease, color .15s ease;
}

.nav-link .icon { font-size: 1.05rem; }

.nav-link:hover { background: var(--bg); color: var(--text); }

.nav-link.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-weight: 600;
    box-shadow: var(--shadow-md);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 12px 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.sidebar-footer span { font-weight: 600; color: var(--text); }

.content {
    flex: 1;
    padding: 28px 32px calc(var(--bottom-nav-height) + 28px);
    max-width: 1280px;
    width: 100%;
}

/* --- Bottom nav (mobile) --- */
.bottom-nav {
    display: none;
}

@media (max-width: 860px) {
    .sidebar { display: none; }

    .content { padding: 18px 16px calc(var(--bottom-nav-height) + 20px); }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bottom-nav-height);
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 16px rgba(23, 24, 63, 0.06);
        z-index: 50;
    }

    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 0.7rem;
        font-weight: 500;
        color: var(--text-muted);
    }

    .bottom-nav a.active { color: var(--primary); }
    .bottom-nav .icon {
        font-size: 1.2rem;
        transition: transform .15s ease;
    }
    .bottom-nav a.active .icon { transform: translateY(-1px) scale(1.08); }
}

/* --- Shared components --- */
h1, h2, h3 { margin-top: 0; letter-spacing: -0.01em; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-header h1 { font-size: 1.5rem; font-weight: 800; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .18s ease, transform .18s ease;
    overflow: hidden;
}

a.card { display: block; color: inherit; }
a.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: transparent; }

.card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 1.05rem;
    margin-bottom: 10px;
    background: var(--info-light);
}

.card-icon-blue { background: var(--info-light); }
.card-icon-amber { background: var(--warning-light); }
.card-icon-purple { background: #f2ecfe; }
.card-icon-red { background: var(--danger-light); }
.card-icon-rose { background: #ffe9ef; }
.card-icon-teal { background: var(--teal-light); }

.card .value {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.card .label {
    color: var(--text-muted);
    font-size: 0.83rem;
    font-weight: 500;
    margin-top: 2px;
}

.card.warn {
    border-color: rgba(225, 29, 72, 0.25);
    box-shadow: 0 0 0 1px rgba(225, 29, 72, 0.08), var(--shadow-sm);
}
.card.warn .value { color: var(--danger); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.panel h2 { font-size: 1.05rem; font-weight: 700; }
.panel h3 { font-size: 0.95rem; font-weight: 700; margin-top: 20px; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th, td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #fafbff;
}

tbody tr { transition: background-color .12s ease; }
tbody tr:hover { background: var(--primary-light); }
tbody tr:last-child td { border-bottom: none; }

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    background: #eef0f4;
    color: var(--text-muted);
}

.badge-urgent, .badge-URGENT { background: var(--danger-light); color: var(--danger); }
.badge-high, .badge-HIGH { background: var(--warning-light); color: var(--warning); }
.badge-medium, .badge-MEDIUM { background: #eef0f4; color: var(--text-muted); }
.badge-low, .badge-LOW { background: var(--success-light); color: var(--success); }

.badge-BUG { background: var(--danger-light); color: var(--danger); }
.badge-FEATURE_REQUEST, .badge-IMPROVEMENT { background: var(--info-light); color: var(--primary-dark); }
.badge-QUESTION { background: #eef0f4; color: var(--text-muted); }

.badge-NEW { background: var(--info-light); color: var(--primary-dark); }
.badge-RESOLVED, .badge-CLOSED { background: var(--success-light); color: var(--success); }

.badge-NOT_ANALYZED { background: var(--warning-light); color: var(--warning); }
.badge-NEEDS_REANALYSIS { background: var(--danger-light); color: var(--danger); }
.badge-ANALYZED { background: var(--success-light); color: var(--success); }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.filters select, .filters input {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    font-size: 0.88rem;
}

.filters select:focus, .filters input:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }

.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}

.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.32);
}
.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--primary), var(--accent)); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #c11346; }
.btn-block { width: 100%; text-align: center; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

form label {
    display: block;
    margin-bottom: 12px;
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 500;
}

form input[type=text], form input[type=email], form input[type=password], form input[type=url],
form textarea, form select {
    width: 100%;
    margin-top: 5px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--surface);
    transition: border-color .12s ease, box-shadow .12s ease;
}

form input:focus, form textarea:focus, form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.messages { margin-bottom: 16px; }

.message {
    padding: 11px 16px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}

.message-success { background: var(--success-light); color: var(--success); }
.message-error { background: var(--danger-light); color: var(--danger); }

.two-col {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 18px;
}

/* Grid/flex items default to min-width:auto, which sizes them to fit their
   content (e.g. a large inline <img>) instead of shrinking to the track/
   flex-basis width. Without this, one big photo in the thread can blow out
   the whole two-column layout and squeeze the AI panel down to a sliver. */
.two-col > .panel {
    min-width: 0;
}

@media (max-width: 860px) {
    .two-col { grid-template-columns: 1fr; }
}

.thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
    min-width: 0;
}

.bubble {
    max-width: 80%;
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 0.9rem;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    min-width: 0;
    box-shadow: var(--shadow-sm);
}

.bubble-customer { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble-staff, .bubble-ai { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25); }
.bubble-system { background: transparent; color: var(--text-muted); align-self: center; font-size: 0.78rem; box-shadow: none; }

.bubble-meta { font-size: 0.7rem; opacity: 0.75; margin-top: 5px; }

/* A fixed px cap (not a %) is intentional: percentage max-width on a
   replaced element doesn't stop it from forcing its ancestors to grow to
   its natural size in a grid/flex context (see .two-col > .panel above).
   A fixed value has no such dependency on an ancestor's own width. */
.bubble-image, .bubble-media {
    max-width: min(260px, 100%);
    max-height: 260px;
    width: auto;
    height: auto;
    border-radius: 10px;
    display: block;
}
.bubble-caption { margin-top: 6px; }

.attention-list { list-style: none; padding: 0; margin: 0; }

.attention-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 13px 4px;
    border-bottom: 1px solid var(--border);
}

.attention-item:last-child { border-bottom: none; }
.attention-item > span:last-child { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }

.empty-state {
    color: var(--text-muted);
    padding: 28px;
    text-align: center;
    font-size: 0.9rem;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(900px 500px at 15% 0%, var(--bg-accent), transparent),
        radial-gradient(700px 400px at 100% 100%, #ded4fb, transparent),
        var(--bg);
    padding: 16px;
}

.login-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.4rem;
}

.login-card h1::before {
    content: "SH";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 0.8rem;
    font-weight: 800;
    box-shadow: var(--shadow-md);
}

.login-card .subtitle { color: var(--text-muted); margin-top: 2px; margin-bottom: 24px; font-size: 0.9rem; }

.field-list dt { font-weight: 700; margin-top: 14px; font-size: 0.85rem; color: var(--text-muted); }
.field-list dd { margin: 4px 0 0; color: var(--text); }

.kv-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 10px 16px;
    font-size: 0.9rem;
}

.kv-grid dt { color: var(--text-muted); font-weight: 500; }
.kv-grid dd { margin: 0; }
