/* ===== Safe area support ===== */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Focus styles ===== */
:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    .animate-spin,
    .animate-pulse,
    .animate-bounce { animation: none; }

    .transition-all,
    .transition-transform,
    .transition-opacity,
    .transition-colors { transition: none !important; }

    .detail-panel,
    .action-sheet,
    .action-sheet-backdrop { transition: none !important; }
}

/* ===== iOS-style segmented control ===== */
.segmented-control {
    display: flex;
    background: rgba(118, 118, 128, 0.12);
    border-radius: 9px;
    padding: 2px;
}

.segmented-control button {
    flex: 1;
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    color: #1c1c1e;
    position: relative;
}

.segmented-control button.active {
    background: white;
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.12);
}

/* ===== Case card ===== */
.case-card {
    background: white;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    border-left: 4px solid transparent;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.case-card:active {
    transform: scale(0.98);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

/* ===== Response debt pulse ===== */
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.debt-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff3b30;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

/* ===== Status pill ===== */
.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* ===== Detail panel slide-in ===== */
.detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: #f2f2f7;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    flex-direction: column;
}

.detail-panel.open {
    transform: translateX(0);
}

/* ===== Action sheet ===== */
.action-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 60;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.action-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.action-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 70;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    padding-bottom: env(safe-area-inset-bottom);
}

.action-sheet.open {
    transform: translateY(0);
}

.action-sheet-card {
    background: white;
    border-radius: 14px 14px 0 0;
    padding: 12px 16px 20px;
}

.action-sheet-option {
    padding: 14px 16px;
    border-radius: 10px;
    font-size: 17px;
    color: #007aff;
    text-align: center;
    transition: background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.action-sheet-option:active {
    background: rgba(0, 122, 255, 0.08);
}

/* ===== Note modal ===== */
.note-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.note-modal-card {
    background: white;
    border-radius: 14px 14px 0 0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    max-height: 70vh;
}

/* ===== Brief item ===== */
.brief-item {
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
    padding: 12px 0;
}

.brief-item:last-child {
    border-bottom: none;
}

/* ===== Search bar ===== */
.search-bar {
    background: rgba(118, 118, 128, 0.12);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 15px;
    border: none;
    width: 100%;
    color: #1c1c1e;
}

.search-bar::placeholder {
    color: #8e8e93;
}

/* ===== Large title ===== */
.large-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #1c1c1e;
}

/* ===== Loading spinner ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0, 122, 255, 0.2);
    border-top-color: #007aff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Group header for significance grouping ===== */
.group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin-top: 12px;
    margin-bottom: 4px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    border-left: 3px solid transparent;
    transition: background 0.15s ease;
}

.group-header:first-child {
    margin-top: 0;
}

.group-header:active {
    background: rgba(255, 255, 255, 0.9);
}

.group-header-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.group-header-chevron.collapsed {
    transform: rotate(-90deg);
}

/* ===== Action buttons grid ===== */
.action-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    transition: transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
    transform: scale(0.96);
}

/* ===== Message box (original messages) ===== */
.message-box {
    background: #1c1c1e;
    color: #e5e5ea;
    border-radius: 12px;
    padding: 14px 16px;
    font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== Suggested response box ===== */
.suggested-response {
    background: #eff6ff;
    border: 1px solid #dbeafe;
    border-radius: 12px;
    padding: 14px 16px;
}

/* ===== Sticky detail header ===== */
.detail-sticky-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(242, 242, 247, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid rgba(60, 60, 67, 0.12);
    padding: 12px 16px 14px;
    margin: 0 -16px;
}

/* ===== Inline chat section ===== */
.chat-section {
    border-top: 1px solid rgba(60, 60, 67, 0.12);
    margin-top: 8px;
    padding-top: 16px;
}

.chat-bubble {
    max-width: 85%;
    border-radius: 16px;
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.5;
}

.chat-bubble-user {
    background: #007aff;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
    background: white;
    color: #1c1c1e;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chat-bubble-error {
    background: #fff1f0;
    color: #ff3b30;
    border-bottom-left-radius: 4px;
    border: 1px solid #ffccc7;
}

.chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 0;
}

/* ===== Reply needed label ===== */
.reply-needed-label {
    font-size: 11px;
    font-weight: 600;
    color: #ff3b30;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* ===== Pull-to-refresh hint ===== */
.pull-refresh-hint {
    display: flex;
    justify-content: center;
    padding: 8px 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.pull-refresh-hint.visible {
    opacity: 1;
}

/* ===== Section header ===== */
.section-header {
    font-size: 13px;
    font-weight: 600;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 0;
}

/* ===== Print styles ===== */
@media print {
    .action-buttons,
    .search-bar,
    .chat-section { display: none !important; }
}

/* ===== Standalone PWA adjustments ===== */
@media all and (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
    }
}
