/* ==========================================================================
   DESIGN TOKENS
   ========================================================================== */
:root {
    /* Professional Green Theme */
    --primary: #10B981;
    /* Emerald 500 */
    --primary-dark: #059669;
    /* Emerald 600 */
    --primary-light: #D1FAE5;
    /* Emerald 100 */

    /* Neutrals - Light Mode */
    --bg-color: #ffffff;
    --card-bg: #f8fafc;
    /* Slate 50 */
    --border-color: #e2e8f0;
    /* Slate 200 */

    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */

    --success: #10b981;
    --error: #ef4444;

    /* Metrics */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);

    /* System Fonts - Privacy Friendly */
    --font-heading: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    --font-body: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* Dark Mode - High Contrast Green on Black */
body.dark-mode {
    --bg-color: #000000;
    --card-bg: #111111;
    --border-color: #333333;

    --text-main: #ffffff;
    --text-muted: #a3a3a3;
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================================================
   APP CONTAINER & HEADER
   ========================================================================== */
.app-container {
    width: 100%;
    max-width: 800px;
    padding: 50px 20px;
    display: flex;
    flex-direction: column;
    gap: 40px;
}

main {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.app-header {
    text-align: center;
    margin-bottom: 20px;
}

.logo-wrapper {
    display: inline-flex;
    padding: 8px;
    margin-bottom: 16px;
}

.logo {
    width: 48px;
    height: 48px;
}

h1 {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 2.2rem;
    color: var(--text-main);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
}

/* ==========================================================================
   CARDS & SECTIONS
   ========================================================================== */
/* Reusing "glass-panel" class name in HTML but styling as solid card */
.glass-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-sm);
}

.section-header {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    color: var(--text-main);
    margin-bottom: 4px;
}

.section-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ==========================================================================
   TABLE STYLES
   ========================================================================== */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-color);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}

th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

td {
    padding: 8px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

tr:last-child td {
    border-bottom: none;
}

/* Inputs in table */
td input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    width: 100%;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-main);
    transition: all 0.2s;
}

td input:hover {
    background: var(--card-bg);
    border-color: var(--border-color);
}

td input:focus {
    outline: none;
    background: var(--bg-color);
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

/* Delete Button */
.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-delete:hover {
    background: #fef2f2;
    color: var(--error);
}

body.dark-mode .btn-delete:hover {
    background: #2a1010;
}

/* ==========================================================================
   CONTROLS AREA
   ========================================================================== */
.controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-family: var(--font-body);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    /* Always white text on green button */
}

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

.total-weight-display {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    background: var(--bg-color);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

/* ==========================================================================
   RESULTS DASHBOARD
   ========================================================================== */
.results-dashboard {
    margin-top: 32px;
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 20px;
}

.result-card {
    background: var(--bg-color);
    border-radius: var(--radius-md);
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid var(--border-color);
}

.result-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.result-value {
    font-family: var(--font-heading);
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

/* Target Section */
.target-section {
    background: var(--bg-color);
    border-radius: var(--radius-md);
    padding: 24px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
}

.input-group-row {
    display: flex;
    gap: 16px;
}

.input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-wrapper label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.input-wrapper input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    font-size: 0.9rem;
    color: var(--text-main);
    transition: all 0.2s;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-color);
    box-shadow: 0 0 0 1px var(--primary);
}

.required-grade-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.required-grade-result[aria-hidden="true"] {
    display: none;
}

.required-grade-result .label {
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.9rem;
}

.required-grade-result .value {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

/* ==========================================================================
   CONVERTER CARD
   ========================================================================== */
.converter-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.converter-inputs {
    display: flex;
    gap: 16px;
}

.converter-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    color: var(--text-main);
    padding: 20px 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--primary);
}

.mini-stat,
.main-stat {
    display: flex;
    flex-direction: column;
}

.mini-stat .label,
.main-stat .label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
}

.mini-stat .value {
    font-size: 1.1rem;
    font-weight: 700;
}

.main-stat {
    text-align: right;
}

.main-stat .value {
    font-size: 2rem;
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1;
    color: var(--primary);
}

/* ==========================================================================
   FOOTER & THEME TOGGLE
   ========================================================================== */
.app-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-md);
}

.theme-toggle:hover {
    background: var(--bg-color);
    border-color: var(--primary);
    color: var(--primary);
}

.theme-icon {
    width: 20px;
    height: 20px;
}

.moon-icon {
    display: none;
}

.sun-icon {
    display: block;
}

body.dark-mode .moon-icon {
    display: block;
}

body.dark-mode .sun-icon {
    display: none;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */
@media (max-width: 700px) {
    .app-container {
        padding: 40px 16px;
    }

    h1 {
        font-size: 1.75rem;
    }

    .results-dashboard {
        grid-template-columns: 1fr;
    }

    .converter-inputs {
        flex-direction: column;
        gap: 16px;
    }

    .input-wrapper.small {
        flex: 1;
    }
}