/* Basic Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Global Styles */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f8f9fa; /* Light Gray Background */
    color: #212529; /* Dark Gray/Black Text */
    line-height: 1.6;
    padding: 20px;
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.75em;
    color: #343a40;
}

a {
    color: #007bff; /* Primary Accent Blue */
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.error-message {
    color: #dc3545; /* Secondary Accent/Destructive Red */
    font-size: 0.9em;
    margin-top: 5px;
}

.success-message {
    color: #28a745; /* Green for success */
    font-size: 0.9em;
    margin-top: 5px;
}
/* General Layout */
.container {
    max-width: 1200px;
    margin: 0 auto; /* Center content */
    padding: 20px;
}

header {
    display: flex; /* Use flexbox */
    flex-direction: column; /* Stack children vertically (h1) */
    justify-content: center; /* Center children vertically in the flex container */
    align-items: center; /* Center children horizontally */
    margin-bottom: 30px;
    padding-top: 15px; /* Adjusted padding - ensure enough total vertical space */
    padding-bottom: 15px; /* Adjusted padding - before the border */
    border-bottom: 1px solid #dee2e6;
    width: 100%;
    box-sizing: border-box;
    min-height: 60px; /* Example: ensure header has some minimum height for stability with flex */
}

header h1 {
    display: block;
    color: #007bff;
    text-align: center; /* Still useful for multi-line text within h1 */
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    box-sizing: border-box;
    padding: 5px 0; /* Minimal vertical padding, no horizontal padding */
    min-width: 0;
    line-height: 1.3; /* Control line height */
    margin: 0; /* Remove default h1 margins to let flexbox control position */
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center; /* 关键：垂直居中 */
    padding: 15px 20px; /* 左右留白 */
    margin-bottom: 20px;
    min-height: 60px;
}

nav h1, nav h2, nav h3, nav h4, nav h5, nav h6 {
    margin: 0;
    color: #007bff;
    font-weight: 500;
    line-height: 1.2;
}

nav h4 {
    font-size: 1.5rem;
}

/* Card Styles */
.card {
    background-color: #ffffff; /* White Card Background */
    border: 1px solid #dee2e6; /* Subtle Border/Lines */
    border-radius: 8px; /* Rounded corners */
    margin-bottom: 20px;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); /* Light shadow for depth */
    transition: box-shadow 0.3s ease-in-out;
    display: flex; /* Added for flex layout within card */
    flex-direction: column; /* Stack content vertically */
}

.card:hover {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.card-header { /* Optional: for a distinct header section in a card */
    padding-bottom: 10px;
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.card-header h2, .card-header h3 {
    margin-bottom: 0; /* Adjusted margin for titles within card header */
    color: #007bff; /* Accent for card titles */
}

.card-content {
    flex-grow: 1; /* Allows content to expand */
}

.card-content p {
    margin-bottom: 10px;
    line-height: 1.5;
}

.card-content strong {
    color: #495057; /* Slightly darker for emphasis */
}

.card-footer { /* Optional: for a distinct footer section in a card */
    padding-top: 15px;
    margin-top: auto; /* Pushes footer to the bottom if card content is short */
    border-top: 1px solid #eee;
}

/* Grid for Cards (Flexbox based) */
.card-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 20px; /* Spacing between cards */
}

.card-grid .card {
    flex: 1 1 calc(33.333% - 20px); /* Three cards per row, adjusting for gap */
    min-width: 300px; /* Minimum width */
}

/* Button Styles */
.btn {
    display: inline-flex; /* Changed from inline-block */
    align-items: center;   /* Vertically center content */
    justify-content: center; /* Horizontally center content */
    font-weight: 500;
    color: #ffffff;
    /* text-align: center; /* No longer strictly needed due to justify-content but doesn't harm */
    /* vertical-align: middle; /* No longer needed */
    cursor: pointer;
    background-color: #007bff;
    border: 1px solid #007bff;
    padding: 10px 20px; /* Keep existing padding, flexbox will center within this */
    font-size: 0.9rem;
    line-height: 1.2; /* Set a specific line-height to help stabilize, may need adjustment */
    border-radius: 6px;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, transform 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn:hover {
    background-color: #0056b3;
    border-color: #0050a0; /* Darker shade for hover */
    text-decoration: none;
    transform: translateY(-1px); /* Slight lift effect */
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.btn:active {
    transform: translateY(0px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.btn-danger {
    background-color: #dc3545;
    border-color: #dc3545;
}

.btn-danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

.btn-block { /* For buttons that take full width of their container */
    display: flex; /* Changed from block to flex */
    width: 100%;
    /* align-items & justify-content will be inherited from .btn if not overridden */
}

.btn-group { /* For grouping buttons */
    display: flex;
    gap: 10px; /* Space between buttons in a group */
}

.btn-group .btn {
    flex-grow: 1; /* Make buttons in a group take equal width */
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}


/* Responsive adjustments for card grid */
@media (max-width: 992px) {
    .card-grid .card {
        flex: 1 1 calc(50% - 20px); /* Two cards per row */
    }
}

@media (max-width: 768px) {
    .card-grid .card {
        flex: 1 1 100%; /* One card per row */
    }
    body {
        padding: 10px;
    }
    .container {
        padding: 10px;
    }
    .btn-group {
        flex-direction: column; /* Stack buttons in a group on small screens */
    }
}

/* Input and Form Control Styling */
input[type="text"],
input[type="url"],
input[type="number"],
input[type="password"],
textarea,
select { /* Added select for consistency */
    display: block;
    width: 100%;
    padding: 10px 12px; /* Adjusted padding */
    margin-bottom: 15px;
    font-size: 1rem;
    font-family: inherit; /* Inherit font from body */
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: 6px; /* More rounded */
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}

input[type="text"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
    border-color: #80bdff; /* Blue focus highlight */
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

textarea {
    min-height: 100px; /* Give textareas a bit more default height */
}

label {
    display: inline-block;
    margin-bottom: 0.5rem;
    font-weight: 500; /* Slightly bolder labels */
    color: #495057;
}

.form-group { /* Wrapper for label and input */
    margin-bottom: 1rem;
}

/* Specific Dashboard adjustments */
#dashboardActions {
    margin-bottom: 30px; /* More space */
    display: flex;
    flex-wrap: wrap; /* Allow buttons to wrap on smaller screens */
    gap: 15px; /* More space between buttons */
    padding: 15px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* API Key Item Styling */
.api-key-item {
    padding: 10px;
    border: 1px solid #eee;
    margin-bottom: 10px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.api-key-item span { /* For text part of key */
    flex-grow: 1;
    margin-right: 10px; /* Add some space between text and button */
}

/* Status Styles (ensure these are comprehensive for ApiKeyStatus) */
.status-VALID { color: #28a745; font-weight: bold; }
.status-INVALID { color: #dc3545; font-weight: bold; }
.status-RATE_LIMITED { color: #ffc107; font-weight: bold; } /* Amber */
.status-UNKNOWN { color: #6c757d; font-weight: bold; } /* Gray */

/* === Additional Responsive Refinements === */

@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem; /* Consistent heading size reduction */
    }

    /* Ensure nav items are properly aligned when stacked */
    nav {
        flex-direction: column;
        align-items: flex-start; /* Align items to the start */
    }

    nav .btn { /* For logout button or any other buttons in nav */
        margin-top: 10px; /* Add space if stacked under title */
        align-self: flex-start; /* Prevent stretching if nav becomes flex container */
    }

    /* Stack dashboard action buttons and make them full width */
    #dashboardActions {
        flex-direction: column;
    }
    #dashboardActions .btn {
        width: 100%;
        margin-bottom: 10px; /* Add margin between stacked buttons */
    }
    #dashboardActions .btn:last-child {
        margin-bottom: 0;
    }

    /* Adjust API key item display on smaller screens */
    .api-key-item {
        flex-direction: column; /* Stack key details and delete button */
        align-items: flex-start; /* Align items to the start */
    }
    .api-key-item .btn-sm { /* Delete button for API key */
        margin-top: 10px; /* Add space when stacked */
        align-self: flex-start; /* Prevent button from stretching */
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem; /* Further reduce heading size */
    }

    .btn { /* Slightly smaller buttons on very small screens */
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .btn-sm { /* Adjust small buttons too */
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .card {
        padding: 15px; /* Reduce padding within cards */
    }

    .card-header {
        padding-bottom: 8px;
        margin-bottom: 12px;
    }

    .card-header h2, .card-header h3, .card-content h4 { /* Reduce card heading sizes */
        font-size: 1.2rem;
    }
    .card-content h4 { /* Specifically for "Current Keys" etc. */
        margin-top: 10px; /* Add some top margin if it's preceded by another element */
    }


    .card-content p, .card-content strong, .card-content span {
        font-size: 0.9rem; /* Slightly adjust paragraph font size */
    }

    /* Make form elements slightly more compact */
    input[type="text"],
    input[type="url"],
    input[type="number"],
    input[type="password"],
    textarea,
    select {
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    label {
        font-size: 0.85rem;
    }

    /* Ensure manage provider page sections stack nicely */
    #manageProviderTitle { /* If this is the h1 on manage provider page */
        font-size: 1.5rem;
    }
}

/* === Interaction Detail: Disabled Button State === */

.btn:disabled,
.btn[disabled] { /* Cover both property and attribute */
    background-color: #ced4da; /* A muted gray */
    border-color: #ced4da;
    color: #6c757d; /* Text color that has enough contrast on the muted gray */
    cursor: not-allowed;
    box-shadow: none; /* Remove any hover/active shadows */
    transform: none; /* Remove any hover/active transforms */
    opacity: 0.65; /* Standard opacity for disabled elements */
}
