/* ERP Query System - Custom Styles */

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --header-bg: #1a3353;
    --header-text: #ffffff;
    --surface: #ffffff;
    --background: #f1f3f4;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --success: #1e8e3e;
    --danger: #d93025;
    --warning: #f9ab00;
    --cyan: #00838f;
}

body {
    background-color: var(--background);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
    color: var(--text-primary);
    margin: 0;
    padding: 0;
}

/* Header / Title Bar */
.erp-header {
    background: linear-gradient(135deg, var(--header-bg) 0%, #2c5282 100%);
    color: var(--header-text);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.erp-header h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.erp-header .logo-icon {
    font-size: 1.6rem;
    margin-right: 10px;
}

.erp-header .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.erp-header .user-info .username {
    opacity: 0.9;
}

.erp-header .erp-badge {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    opacity: 0.85;
}

.erp-header .btn-logout {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    padding: 4px 14px;
    border-radius: 4px;
    font-size: 0.85rem;
    text-decoration: none;
    transition: background 0.2s;
}

.erp-header .btn-logout:hover {
    background: rgba(255,255,255,0.25);
}

/* Search Card */
.search-card {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 20px 24px;
    margin: 20px auto;
    max-width: 1400px;
}

.search-card .search-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.search-card .form-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.search-card label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.search-card select,
.search-card input[type="text"] {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.search-card select {
    min-width: 180px;
    background-color: #fff;
    cursor: pointer;
}

.search-card input[type="text"] {
    min-width: 120px;
}

.search-card input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.search-card .search-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-left: 4px;
}

.search-card .search-status {
    margin-left: auto;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Loading spinner */
.loading-spinner {
    display: none;
    align-items: center;
    gap: 8px;
    color: var(--primary);
    font-size: 0.9rem;
}

.loading-spinner.active {
    display: inline-flex;
}

.loading-spinner .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* Result area */
.result-container {
    max-width: 1400px;
    margin: 0 auto 24px auto;
    padding: 0 16px;
}

/* Status badges */
.badge-success {
    background-color: var(--success);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-error {
    background-color: var(--danger);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* Table improvements */
.w3-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 0.9rem;
}

.w3-table thead tr {
    background: var(--header-bg) !important;
    color: white;
}

.w3-table thead th {
    padding: 10px 12px;
    font-weight: 500;
    font-size: 0.85rem;
    text-align: left;
    white-space: nowrap;
    border-bottom: 2px solid var(--primary-dark);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--header-bg);
}

.w3-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.w3-table tbody tr:hover {
    background-color: var(--primary-light) !important;
}

.w3-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

/* Override w3-blue for table headers */
.w3-table tr.w3-blue {
    background: var(--header-bg) !important;
}

/* Buttons in tables */
.w3-table .btn-light {
    padding: 2px 8px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    transition: all 0.15s;
}

.w3-table .btn-light:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    text-decoration: none;
}

/* Sub-page headers */
.page-header {
    background: linear-gradient(135deg, var(--cyan) 0%, #00acc1 100%);
    color: white;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.page-header h1 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 600;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-header .btn-export {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.page-header .btn-export:hover {
    background: rgba(255,255,255,0.3);
}

.page-header .btn-back {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    padding: 6px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s;
    cursor: pointer;
}

.page-header .btn-back:hover {
    background: rgba(255,255,255,0.35);
}

/* Summary badges at bottom */
.result-summary {
    text-align: center;
    margin: 16px auto;
    max-width: 1400px;
}

.result-summary h3 {
    display: inline-block;
    padding: 8px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
}

.result-summary .w3-blue {
    background: var(--primary) !important;
    color: #fff;
}

.result-summary .w3-red {
    background: var(--danger) !important;
    color: #fff;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .erp-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .search-card .search-row {
        flex-direction: column;
        align-items: stretch;
    }

    .search-card .form-group {
        width: 100%;
    }

    .search-card input[type="text"],
    .search-card select {
        flex: 1;
        min-width: 0;
    }

    .search-card .search-status {
        margin-left: 0;
        justify-content: center;
    }

    .page-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .w3-table {
        font-size: 0.8rem;
    }

    .w3-table thead th,
    .w3-table tbody td {
        padding: 6px 8px;
    }
}

/* Keyboard shortcut hint */
.kbd {
    display: inline-block;
    background: #eee;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 1px 5px;
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Search action buttons */
.search-actions {
    display: flex;
    gap: 6px;
}

.btn-search {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-search:hover {
    background: var(--primary-dark);
}

.btn-clear {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-clear:hover {
    background: #f1f3f4;
    color: var(--text-primary);
}

/* Export button */
.btn-export {
    background: transparent;
    color: var(--success);
    border: 1px solid var(--success);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-export:hover {
    background: var(--success);
    color: #fff;
}

/* Search term highlight */
.search-highlight {
    background: #fff176;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

/* Active query field highlight */
.search-input.active-query {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    margin: 4px 0;
    font-size: 1rem;
}

.empty-state .empty-state-sub {
    font-size: 0.85rem;
    opacity: 0.7;
}

/* Print styles */
@media print {
    .erp-header,
    .search-card,
    .page-header .btn-back,
    .btn-logout,
    .empty-state,
    #dbg_msg,
    .btn-light {
        display: none !important;
    }

    .page-header {
        background: none !important;
        color: #000 !important;
        box-shadow: none !important;
        padding: 8px 0;
        border-bottom: 2px solid #000;
    }

    .page-header h1 {
        color: #000 !important;
        font-size: 1.1rem;
    }

    body {
        background: #fff !important;
    }

    .result-container {
        max-width: none;
        padding: 0;
    }

    .w3-table thead tr,
    .w3-table thead th {
        background: #eee !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .w3-table tbody tr:hover {
        background: none !important;
    }

    .w3-table {
        font-size: 0.8rem;
    }

    .result-summary h3 {
        color: #000 !important;
        background: none !important;
        border: 1px solid #000;
    }
}

/* Scrollable table wrapper for sub-pages */
.result-container table {
    min-width: 100%;
}

@media (max-width: 768px) {
    .result-container {
        overflow-x: auto;
    }

    .search-actions {
        width: 100%;
    }

    .btn-search {
        flex: 1;
    }
}

/* Part number - clickable for copy */
.part-number {
    font-family: "Consolas", "Monaco", monospace;
    font-weight: 600;
    color: var(--primary-dark);
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 3px;
    transition: background 0.15s;
}

.part-number:hover {
    background: var(--primary-light);
}

/* Copy toast notification */
.copy-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(32, 33, 36, 0.9);
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    z-index: 9999;
    pointer-events: none;
}

/* Item attribute badges */
.attr-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.attr-purchase {
    background: #e3f2fd;
    color: #1565c0;
}

.attr-manufacture {
    background: #e8f5e9;
    color: #2e7d32;
}

.attr-outsource {
    background: #fff3e0;
    color: #e65100;
}

.attr-virtual {
    background: #f3e5f5;
    color: #7b1fa2;
}

.attr-feature {
    background: #e0f7fa;
    color: #00838f;
}

.attr-option {
    background: #fce4ec;
    color: #c62828;
}

/* Material type badges */
.mat-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.mat-direct {
    background: #e8f5e9;
    color: #2e7d32;
}

.mat-indirect {
    background: #fff8e1;
    color: #f57f17;
}

.mat-vendor {
    background: #e3f2fd;
    color: #1565c0;
}

.mat-none {
    background: #fafafa;
    color: #9e9e9e;
}

.mat-customer {
    background: #fce4ec;
    color: #c62828;
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.status-open {
    background: #fff3e0;
    color: #e65100;
}

.status-closed {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-forced {
    background: #fce4ec;
    color: #c62828;
}

.status-pending {
    background: #f3e5f5;
    color: #7b1fa2;
}

.status-issued {
    background: #e3f2fd;
    color: #1565c0;
}

.status-producing {
    background: #fff8e1;
    color: #f57f17;
}

/* No access warning */
.no-access-warning {
    max-width: 1400px;
    margin: 16px auto;
    padding: 16px 24px;
    background: #fff3e0;
    border: 1px solid #ffb74d;
    border-radius: 8px;
    color: #e65100;
    font-size: 0.9rem;
    line-height: 1.6;
    text-align: center;
}

/* Virtual item (虛設件) row highlight - 使用高優先級選擇器確保覆蓋 w3-striped */
.w3-table tbody tr.virtual-row,
.w3-table tbody tr.virtual-row:nth-child(even),
.w3-table tbody tr.virtual-row:nth-child(odd),
tr.virtual-row {
    background-color: #f3e5f5 !important;
}

.w3-table tbody tr.virtual-row:hover,
tr.virtual-row:hover {
    background-color: #e1bee7 !important;
}


/* Price hidden indicator */
.price-hidden {
    color: #bdbdbd;
    font-style: italic;
    cursor: default;
}

/* Stock level indicators */
.stock-zero .btn-light {
    color: var(--text-secondary);
    font-style: italic;
}

.stock-has .btn-light {
    color: var(--success);
    font-weight: 600;
}

.stock-has .btn-light:hover {
    color: #fff;
}

/* Sortable table headers */
.w3-table thead th {
    cursor: pointer;
    user-select: none;
    position: relative;
}

.w3-table thead th::after {
    content: "";
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
    font-size: 0.7rem;
}

.w3-table thead th:hover::after {
    content: "\2195";
    opacity: 0.6;
}

.w3-table thead th.sort-asc::after {
    content: "\25B2";
    opacity: 1;
}

.w3-table thead th.sort-desc::after {
    content: "\25BC";
    opacity: 1;
}

/* Search history */
.search-history {
    max-width: 1400px;
    margin: -8px auto 0 auto;
    padding: 0 24px 12px 24px;
}

.search-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.search-history-title {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.history-clear-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
}

.history-clear-btn:hover {
    color: var(--danger);
}

.history-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.history-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-primary);
}

.history-tag:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.history-tag .history-label {
    color: var(--text-secondary);
    font-size: 0.7rem;
    margin-right: 2px;
}

/* Scroll-to-top button */
.scroll-top-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--header-bg);
    color: #fff;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: background 0.2s;
    z-index: 500;
}

.scroll-top-btn:hover {
    background: var(--primary);
}

/* Breadcrumb navigation on sub-pages */
.breadcrumb-nav {
    font-size: 0.78rem;
    margin-bottom: 4px;
    opacity: 0.85;
}

.breadcrumb-nav a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
}

.breadcrumb-nav a:hover {
    color: #fff;
    text-decoration: underline;
}

.breadcrumb-sep {
    margin: 0 6px;
    opacity: 0.5;
}

/* Retry button in error badge */
.btn-retry {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.5);
    color: #fff;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    margin-left: 8px;
    transition: background 0.2s;
}

.btn-retry:hover {
    background: rgba(255,255,255,0.35);
}

/* Focus outlines for accessibility */
.search-input:focus,
.btn-search:focus,
.btn-clear:focus,
.btn-export:focus,
select:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media print {
    .search-history,
    .scroll-top-btn,
    .copy-toast,
    .btn-export,
    .btn-retry,
    .breadcrumb-nav {
        display: none !important;
    }
    .search-highlight {
        background: transparent !important;
    }
}
