/* ================================================
   Ticket Generator — Stylesheet
   ================================================ */

/* ── Reset & Base ───────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #f4f6f9;
    --surface:   #ffffff;
    --primary:   #4f46e5;
    --primary-h: #4338ca;
    --accent:    #06b6d4;
    --text:      #1e293b;
    --text-sec:  #64748b;
    --border:    #e2e8f0;
    --success:   #22c55e;
    --warning:   #f59e0b;
    --danger:    #ef4444;
    --radius:    10px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body {
    font-family: 'Segoe UI', 'Noto Sans TC', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ── Top Bar ────────────────────────────────── */
.top-bar {
    background: var(--primary);
    color: #fff;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.top-bar h1 { font-size: 1.25rem; font-weight: 700; }
.nav-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: .9rem;
    margin-left: 8px;
    transition: .2s;
}
.nav-btn:hover, .nav-btn.active {
    background: rgba(255,255,255,.2);
    border-color: #fff;
}

/* ── Layout ─────────────────────────────────── */
.container {
    max-width: 960px;
    margin: 24px auto;
    padding: 0 16px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}
.card h2 {
    font-size: 1.15rem;
    margin-bottom: 16px;
    color: var(--primary);
}

/* ── Tabs ───────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Form ───────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.required { color: var(--danger); }

input[type="text"],
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    font-family: inherit;
    transition: border .2s;
}
input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}
.checkbox-row label {
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.custom-platform { margin-top: 8px; }

/* ── Buttons ────────────────────────────────── */
.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
    width: 100%;
}
.btn-primary:hover { background: var(--primary-h); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-sm {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 5px 14px;
    border-radius: 6px;
    font-size: .82rem;
    cursor: pointer;
    transition: background .2s;
}
.btn-sm:hover { opacity: .85; }

/* ── Result layout: navigator + tickets ─────── */
.result-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* Sticky ticket navigator (left sidebar) */
.ticket-nav {
    width: 200px;
    flex-shrink: 0;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    position: sticky;
    top: 68px;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
}
.ticket-nav-title {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-sec);
    margin-bottom: 10px;
}
#ticketNavList {
    list-style: none;
    padding: 0;
    margin: 0 0 12px 0;
}
#ticketNavList li a {
    display: block;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: .82rem;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background .15s;
}
#ticketNavList li a:hover { background: var(--bg); color: var(--primary); }
#ticketNavList li.nav-epic a { font-weight: 700; color: #5b21b6; }
#ticketNavList li.nav-story a { padding-left: 16px; border-left: 2px solid var(--border); margin-left: 4px; }

.copy-all-btn {
    width: 100%;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 0;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.copy-all-btn:hover { background: var(--primary-h); }

/* Tickets column fills remaining width */
.tickets-column { flex: 1; min-width: 0; }

/* Card collapse */
.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title-row h2 { margin-bottom: 0; }
.collapse-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: .8rem;
    cursor: pointer;
    color: var(--text-sec);
    white-space: nowrap;
}
.collapse-btn:hover { background: var(--bg); }
.card-body.collapsed { display: none; }

/* ── Result cards ───────────────────────────── */
.result-epic { border-left: 5px solid var(--primary); }

.story-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 24px;
    margin-bottom: 12px;
    border-left: 5px solid var(--accent);
    transition: box-shadow .15s;
}
.story-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }

.story-card-header {
    margin-bottom: 0;
    padding: 4px 0;
}
.story-card-header:hover .collapse-btn { background: var(--bg); }

.story-card-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}
.story-preview-title {
    font-size: .93rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 480px;
}
.card-body { padding-top: 16px; }
.card-body.collapsed { display: none; padding-top: 0; }

/* Hide duplicate ticket-header inside story cards (badges shown in collapsed header) */
.story-inner-content .ticket-header { display: none; }

/* Responsive: hide navigator on small screens */
@media (max-width: 760px) {
    .result-layout { flex-direction: column; }
    .ticket-nav { width: 100%; position: static; max-height: none; }
}

/* ── Ticket header (badges) ─────────────────── */
.ticket-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .3px;
}
.badge-epic     { background: #ede9fe; color: #5b21b6; }
.badge-story    { background: #e0f2fe; color: #0369a1; }
.badge-platform { background: #dcfce7; color: #166534; }
.ticket-id      { font-size: .82rem; color: var(--text-sec); font-family: monospace; }

/* ── Ticket fields ────────────────────────── */
.field-block { margin-bottom: 16px; }
.field-label {
    font-weight: 700;
    font-size: .84rem;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}
.field-summary {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    background: #f8fafc;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.field-desc {
    font-size: .9rem;
    line-height: 1.8;
    white-space: pre-wrap;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    max-height: 480px;
    overflow-y: auto;
}
.field-value {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    white-space: pre-wrap;
    font-size: .93rem;
    line-height: 1.7;
}

/* ── History ────────────────────────────────── */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.history-item:hover { background: #f8fafc; }
.history-meta { font-size: .82rem; color: var(--text-sec); }
.history-check-label {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 2px 4px;
}
.history-check-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
.history-delete-btn {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .15s;
    font-size: .9rem;
    padding: 3px 8px;
}
.history-item:hover .history-delete-btn { opacity: 1; }

/* ── Misc ───────────────────────────────────── */
.muted { color: var(--text-sec); font-style: italic; }
pre { white-space: pre-wrap; word-break: break-word; font-size: .88rem; }

.copy-btn {
    float: right;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: .8rem;
    cursor: pointer;
    color: var(--text-sec);
}
.copy-btn:hover { background: var(--bg); }

/* ── Editable fields ────────────────── */
.field-editable {
    cursor: text;
    transition: border-color .15s, box-shadow .15s;
}
.field-editable:hover {
    border-color: #94b4e8;
    background: #fafcff;
}
.field-editable:focus {
    outline: none;
    border-color: #4f8ef7;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 142, 247, .15);
}

/* ── Save button ──────────────────── */
.save-btn {
    margin-left: auto;
    background: #4f8ef7;
    border: none;
    border-radius: 6px;
    padding: 4px 14px;
    font-size: .8rem;
    cursor: pointer;
    color: #fff;
    font-weight: 600;
}
.save-btn:hover { background: #2d72e8; }
.save-btn:disabled { background: #a0b8e8; cursor: not-allowed; }

/* ── Top-bar right cluster ───────────────────── */
.top-bar-right { display: flex; align-items: center; gap: 16px; }

/* ── Jira header chip ────────────────────────── */
.jira-header-chip { display: flex; align-items: center; gap: 6px; font-size: .85rem; }
.jira-chip-loading { color: rgba(255,255,255,.6); font-size: .82rem; }
.jira-chip-btn {
    background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    padding: 5px 13px;
    border-radius: 6px;
    cursor: pointer;
    font-size: .85rem;
    transition: background .15s;
}
.jira-chip-btn:hover { background: rgba(255,255,255,.28); }
.jira-chip.connected {
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.35);
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: .82rem;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.jira-chip-logout {
    background: transparent;
    border: 1px solid rgba(255,255,255,.35);
    color: rgba(255,255,255,.75);
    padding: 3px 9px;
    border-radius: 5px;
    cursor: pointer;
    font-size: .78rem;
    transition: .15s;
}
.jira-chip-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Jira Login Modal ────────────────────────── */
.jira-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
}
.jira-modal {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    width: 420px;
    max-width: 95vw;
    overflow: hidden;
}
.jira-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    background: #0052cc;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
}
.jira-modal-close {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.8);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.jira-modal-close:hover { color: #fff; }
.jira-modal-body { padding: 20px; }

/* ── Jira Panel ──────────────────────────────── */
.jira-panel { border-left: 5px solid #0052cc; margin-top: 20px; }
.jira-panel h2 { color: #0052cc; margin-bottom: 0; }
.jira-login-form { max-width: 480px; }
.jira-hint-link { font-size: .82rem; color: var(--primary); text-decoration: none; font-weight: 400; }
.jira-hint-link:hover { text-decoration: underline; }
.jira-auth-bar {
    display: flex; align-items: center; justify-content: space-between;
    background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px;
    padding: 8px 14px; margin-bottom: 16px; font-size: .9rem;
}
.jira-types-row { display: flex; gap: 16px; margin-bottom: 8px; }
.jira-types-row .form-group { flex: 1; }
.jira-list-header {
    display: flex; align-items: center; justify-content: space-between;
    margin: 16px 0 8px;
}
.jira-ticket-row {
    padding: 8px 12px; border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 6px; background: #fafafa;
}
.jira-ticket-row:hover { background: #f1f5f9; }
.jira-checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; }
.jira-ticket-title {
    font-size: .88rem; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.jira-results-area { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 16px; }
.jira-result-row {
    padding: 8px 12px; border-radius: 6px; margin-bottom: 6px;
    font-size: .9rem; display: flex; align-items: center; gap: 8px;
}
.jira-result-row.success { background: #f0fdf4; border: 1px solid #bbf7d0; }
.jira-result-row.error   { background: #fef2f2; border: 1px solid #fecaca; }
.jira-result-row a { color: #0052cc; text-decoration: none; }
.jira-result-row a:hover { text-decoration: underline; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 600px) {
    .top-bar { flex-direction: column; gap: 8px; }
    .checkbox-row { flex-direction: column; }
}
