/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
/* Global Scrollbar Hiding */
::-webkit-scrollbar { display: none; }
* { -ms-overflow-style: none; scrollbar-width: none; }

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background-color: #f5f5f5; 
    color: #333; 
    max-width: 600px; 
    margin: 0 auto; 
    height: 100vh; 
    overflow: hidden; 
    display: flex;
    flex-direction: column;
}

/* Disclaimer */
.disclaimer-bar {
    background-color: #fffbe6;
    color: #d48806;
    font-size: 12px;
    height: 30px;
    line-height: 30px;
    overflow: hidden;
    position: relative;
    width: 100%;
    border-bottom: 1px solid #ffe58f;
    flex-shrink: 0;
}
.disclaimer-content {
    display: inline-block;
    white-space: nowrap;
    animation: scroll-left 25s linear infinite;
    padding-left: 100%;
}
@keyframes scroll-left {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

/* Header */
.header { background: linear-gradient(to right, #ffd04b, #ffbd20); padding: 12px 16px 10px 16px; color: #333; flex-shrink: 0; }
.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.app-title { font-size: 16px; font-weight: bold; }
.total-section { display: flex; justify-content: space-between; align-items: flex-end; }
.total-item { flex: 1; }
.total-label { font-size: 12px; opacity: 0.8; margin-bottom: 2px; }
.total-value { font-size: 26px; font-weight: bold; }
.total-profit { text-align: right; }
.total-profit .total-value { font-size: 20px; }

/* ====== Group Tabs ====== */
.group-tabs-wrapper {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 0;
}
.group-tabs-label {
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    padding: 2px 4px;
    flex-shrink: 0;
    margin-right: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.group-label-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    border: none;
    color: #7a6520;
    font-size: 14px;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s;
}
.group-label-btn.text-btn {
    width: auto;
    height: 24px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    padding: 0 8px;
    background-color: transparent;
    box-shadow: none;
    color: #5c4b18;
}
.group-vert-line {
    width: 1px;
    height: 14px;
    background: rgba(92, 75, 24, 0.2);
    margin: 0 4px;
}
.group-label-btn:hover { background: rgba(255,255,255,0.3); }
.group-label-btn:active { opacity: 0.6; transform: scale(0.96); }
.group-label-btn svg { width: 16px; height: 16px; fill: #5c4b18; }
.group-tabs-scroll {
    flex: 1;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    cursor: grab;
}
.group-tabs-scroll::-webkit-scrollbar { display: none; }
.group-tabs-scroll.dragging { cursor: grabbing; }
.group-tabs-inner {
    display: inline-flex;
    gap: 6px;
}
.group-tab {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 14px;
    font-size: 12px;
    cursor: pointer;
    background: rgba(255,255,255,0.35);
    color: #333;
    border: none;
    white-space: nowrap;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.group-tab:active { opacity: 0.7; }
.group-tab.active {
    background: #fff;
    font-weight: bold;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Group Management Modal */
.group-manage-list {
    max-height: 300px;
    overflow-y: auto;
}
.group-manage-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f5f5f5;
    gap: 8px;
}
.group-manage-item:last-child { border-bottom: none; }
.group-manage-name {
    flex: 1;
    font-size: 14px;
    color: #333;
}
.group-manage-name.default { color: #999; }
.group-manage-count {
    font-size: 12px;
    color: #999;
    margin-right: 8px;
}
.group-manage-btn {
    padding: 4px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    color: #666;
}
.group-manage-btn:active { background: #f5f5f5; }
.group-manage-btn.danger { color: #e74c3c; border-color: #fdd; }
.group-manage-btn.danger:active { background: #fff5f5; }

/* Group select dropdown in modals */
.form-select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    outline: none;
    font-size: 16px;
    background: #fff;
    color: #333;
    appearance: auto;
    -webkit-appearance: auto;
}
.form-select:focus { border-color: #ffbd20; }

/* List Header */
.list-header { background: #fff; padding: 10px 20px; display: flex; justify-content: space-between; font-size: 12px; color: #999; border-bottom: 1px solid #eee; align-items: center; flex-shrink: 0;}
.col-action { flex: 1.2; display: flex; gap: 15px; align-items: center; }
.icon-btn { cursor: pointer; width: 20px; height: 20px; fill: #666; }
.col-val { flex: 0.8; text-align: right; display: flex; align-items: center; justify-content: center; /* Default center */ }

.col-val.align-right {
    justify-content: flex-end;
}
.header-sort-box {
    display: flex;
    flex-direction: column;
    margin-left: 4px;
    justify-content: center;
    height: 14px;
}
.sort-arrow {
    width: 0; 
    height: 0; 
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    cursor: pointer;
    opacity: 0.2;
    margin: 1px 0;
}
.sort-arrow.active {
    opacity: 1;
    border-color: #333 transparent transparent transparent;
}
.sort-arrow:hover {
    opacity: 0.6;
}
/* Up Arrow (Triangle Pointing Up) */
.sort-arrow.up {
    border-bottom: 5px solid #333;
    border-top: none;
}
/* Down Arrow (Triangle Pointing Down) */
.sort-arrow.down {
    border-top: 5px solid #333;
    border-bottom: none;
}

/* Scrollable container */
.scroll-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: #fff;
    padding-bottom: 80px; /* Increased to prevent bottom nav (50px) obstruction */
}

.scroll-container.has-bottom-bar {
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: #fff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #eee;
    z-index: 100;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    text-decoration: none;
    font-size: 10px;
    flex: 1;
    height: 100%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
    color: #333;
    font-weight: bold;
}

.nav-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 2px;
    fill: currentColor;
}

/* Edit Actions Footer */
.edit-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #eee;
    height: 60px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    z-index: 200; /* Above bottom nav */
    max-width: 600px;
    margin: 0 auto;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 12px;
    cursor: pointer;
    gap: 4px;
    flex: 1;
    text-align: center;
    padding: 5px 0;
}
.action-btn:active { background-color: #f9f9f9; }
.action-btn svg { width: 20px; height: 20px; margin-bottom: 2px; }

/* Modal */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 100; align-items: center; justify-content: center; }
.modal { 
    background: #fff; 
    padding: 20px; 
    border-radius: 12px; 
    width: 85%; 
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    animation: modalPop 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes modalPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal h3 { margin-bottom: 15px; font-size: 18px; text-align: center; }
.modal p { margin-bottom: 25px; color: #666; font-size: 15px; text-align: center; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-size: 14px; color: #666; }
.form-input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; outline: none; font-size: 16px;}
.form-input:focus { border-color: #ffbd20; }

.modal-btns { display: flex; gap: 10px; margin-top: 20px;}
.btn-cancel { flex:1; padding: 10px; border: none; background: #f5f5f5; border-radius: 6px; cursor: pointer; color: #666; font-size: 15px;}
.btn-confirm { flex:1; padding: 10px; border: none; background: #ffbd20; border-radius: 6px; font-weight: bold; cursor: pointer; color:#333; font-size: 15px;}
.btn-danger { background: #ffebee; color: #d32f2f; }
.btn-danger:hover { background: #ffcdd2; }

/* QR Modal */
.qr-modal-content {
    background-color: #fff;
    margin: 20% auto;
    padding: 30px;
    border-radius: 12px;
    width: 80%;
    max-width: 300px;
    text-align: center;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.qr-code-box {
    margin: 20px auto;
    padding: 10px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    display: inline-block;
}
.qr-url-text {
    background: #f5f5f5;
    padding: 10px;
    border-radius: 4px;
    font-family: monospace;
    margin: 15px 0;
    word-break: break-all;
    font-size: 14px;
    color: #666;
    user-select: text;
}
.copy-btn {
    background: #fcaa00;
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
}
.copy-btn:active { background: #e59b00; }

/* Edit Mode */
.check-mode .fund-item { padding-left: 10px; }
.check-col { display: none; margin-right: 10px; align-items: center; }
.check-mode .check-col { display: flex; align-items: center; }
.sort-btns { display: none; flex-direction: column; gap: 5px; margin-left: 5px;}
.check-mode .sort-btns { display: flex; }
.sort-btn { font-size: 12px; line-height: 1; color: #999; cursor: pointer; width: 20px; text-align: center;}

.pin-btn {
    cursor: pointer;
    margin-left: 10px;
    color: #ddd;
    display: flex;
    align-items: center;
    width: 24px;
    height: 24px;
}
.pin-btn svg {
    fill: currentColor;
    width: 20px;
    height: 20px;
}
.pin-btn.pinned {
    color: #f39c12; /* Orange for pinned */
}

/* Fund List */
.fund-list { background: #fff; }
.fund-item { padding: 15px 20px; border-bottom: 1px solid #eee; display: flex; align-items: center; justify-content: space-between; }
.fund-info { flex: 1.2; }
.fund-name { font-size: 16px; margin-bottom: 5px; color: #333; font-weight: 500;}

/* Revised Fund Code & Tag Layout */
.fund-code { font-size: 12px; color: #999; display: flex; flex-direction: column; gap: 2px; }
.code-row { font-family: monospace; display: flex; align-items: center; gap: 5px; }
.hold-row { font-size: 12px; opacity: 0.8;color: #222222; }

.tag { border: 1px solid #4caf50; background: #4caf50; color: white; font-size: 10px; padding: 0 3px; border-radius: 2px; display: inline-block; line-height: 1.2; transform: scale(0.9); transform-origin: left center;}

  .industry-tag {
      font-size: 10px;
      padding: 1px 4px;
      border-radius: 4px;
      background: #fffbe6;
      color: #d46b08;
      border: 1px solid #ffe58f;
      display: none;
      line-height: normal;
      transform: scale(0.9);
      transform-origin: left center;
      white-space: nowrap;
      margin-left: 2px;
  }/* match header: name 1.2, other columns 0.8 */
.fund-data { flex: 0.8; text-align: right; }
.fund-data-top { font-size: 18px; font-weight: bold; margin-bottom: 2px; }
.fund-data-bottom { font-size: 12px; }

.c-red { color: #e74c3c; }
.c-green { color: #2ecc71; }
.c-gray { color: #999; }
.c-blue { color: #007bff; }

/* Mobile Responsive */
@media (max-width: 480px) {
    .scroll-container {
        /* Adjust for mobile if needed, though 100vh works well */
    }
}

/* ===== Narrow Screen Adaptation (small Android phones) ===== */
/* Medium-narrow screens (360-414px) */
@media (max-width: 414px) {
    .header { padding: 10px 12px 16px 12px; }
    .total-value { font-size: 22px; }
    .total-profit .total-value { font-size: 17px; }
    .total-label { font-size: 11px; }
    .app-title { font-size: 14px; }

    .list-header { padding: 8px 12px; font-size: 11px; }
    .col-action { gap: 10px; }

    .fund-item { padding: 12px 12px; }
    .fund-name { font-size: 14px; margin-bottom: 3px; }
    .fund-code { font-size: 11px; }
    .hold-row { font-size: 11px; }
    .fund-data-top { font-size: 15px; }
    .fund-data-bottom { font-size: 11px; }
    .tag { font-size: 9px; }
    .industry-tag { font-size: 9px; padding: 0px 3px; transform: scale(0.8); }

    .fund-info { flex: 1.1 !important; }
    .fund-data { flex: 0.7 !important; }

    .modal-card { width: 94%; }
    .app-confirm-box { width: 85%; }
    .app-confirm-msg { font-size: 14px; }
    .app-confirm-btns button { font-size: 14px; }
}

/* Very narrow screens (<360px) */
@media (max-width: 360px) {
    .header { padding: 8px 10px 12px 10px; }
    .header-top { margin-bottom: 8px; }
    .total-value { font-size: 20px; }
    .total-profit .total-value { font-size: 15px; }
    .total-label { font-size: 10px; }
    .app-title { font-size: 13px; }

    .list-header { padding: 6px 10px; font-size: 10px; }
    .col-action { gap: 8px; }
    .icon-btn { width: 18px; height: 18px; }

    .fund-item { padding: 10px 10px; }
    .fund-name { font-size: 13px; margin-bottom: 2px; }
    .fund-code { font-size: 10px; }
    .code-row { gap: 3px; }
    .hold-row { font-size: 10px; }
    .fund-data-top { font-size: 14px; }
    .fund-data-bottom { font-size: 10px; }
    .tag { font-size: 8px; padding: 0 2px; }
    .industry-tag { font-size: 8px; padding: 0px 2px; transform: scale(0.8); }

    .fund-info { flex: 1 !important; }
    .fund-data { flex: 0.65 !important; }

    .check-col { width: 28px; min-width: 28px; }
    .pin-btn svg { width: 14px; height: 14px; }
    .fund-check { width: 15px; height: 15px; }

    .disclaimer-bar { height: 24px; line-height: 24px; font-size: 10px; }
    .bottom-nav { height: 44px; }
    .nav-item { font-size: 9px; }
    .nav-item svg { width: 20px; height: 20px; }

    .modal-card { width: 96%; padding: 15px; }
    .modal-title { font-size: 16px; }
    .form-group { margin-bottom: 12px; }
    .form-label { font-size: 12px; }
    .form-input { font-size: 14px; padding: 8px; }
    .app-confirm-box { width: 88%; }
    .app-confirm-msg { font-size: 13px; }
    .app-confirm-btns button { font-size: 13px; padding: 9px; }
}

/* ====== Global Toast ====== */
.app-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 80%;
    text-align: center;
    z-index: 99999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    word-break: break-word;
}
.app-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ====== Global Confirm Dialog ====== */
.app-confirm-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99998;
    align-items: center;
    justify-content: center;
}
.app-confirm-overlay.show {
    display: flex;
}
.app-confirm-box {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    width: 80%;
    max-width: 300px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    animation: modalPop 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
.app-confirm-msg {
    font-size: 15px;
    color: #333;
    text-align: center;
    margin-bottom: 20px;
    line-height: 1.5;
    word-break: break-word;
}
.app-confirm-btns {
    display: flex;
    gap: 10px;
}
.app-confirm-btns button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
}
.app-confirm-cancel {
    background: #f5f5f5;
    color: #666;
}
.app-confirm-ok {
    background: #ffbd20;
    color: #333;
    font-weight: bold;
}

/* AI Link Buttons */
.ai-link-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 16px;
    color: #7c3aed;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-link-btn:hover {
    background: #7c3aed;
    color: #fff;
    border-color: #7c3aed;
}

/* AI Icon Button in header */
.ai-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    height: 20px;
    background: linear-gradient(135deg, #6d28d9 0%, #7c3aed 45%, #c026d3 100%);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    font-family: 'Arial Black', 'Arial', sans-serif;
    border-radius: 4px;
    cursor: pointer;
    letter-spacing: 1px;
    line-height: 1;
    user-select: none;
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.45), inset 0 1px 0 rgba(255,255,255,0.15);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.ai-icon-btn:hover, .ai-icon-btn:active {
    background: linear-gradient(135deg, #6d28d9 0%, #7c3aed 45%, #c026d3 100%);
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.45), inset 0 1px 0 rgba(255,255,255,0.15);
}